从日期时间列创建新列

发布于 2024-08-04 18:00:20 字数 443 浏览 0 评论 0原文

这是我的 SSIS 练习,

我有一个 DATETIME 列,我想要的是从“ DATETIME ”列获取月份和年份并将其加载到名为“Month_Year”的新列中,然后从同一“ DATETIME ”获取日期并加载它进入一个名为“day”的新列

直观

  1. 地源列:

DATETIME

  1. 目标列:

Month_Year Day

底线是我需要将 DATETIME 分成两列 Month_Year 和 Day。

示例

DATETIME
2010-01-01

Month_YEAR     DAY
201001         01`

源列是 2010-01-01 目标列将为 201001 和 01

This is my SSIS excerise

I have a DATETIME column, what I want is to get the Month and Year from " DATETIME " column and load it into a new column called “Month_Year” and then get day from the same " DATETIME " and load it into a new column called "day"

Visually

  1. Source Column:

DATETIME

  1. Destination Column:

Month_Year Day

Bottom line is I need to break DATETIME into two column Month_Year and Day.

Example

DATETIME
2010-01-01

Month_YEAR     DAY
201001         01`

The Source Column is 2010-01-01
The Destination Columns will be 201001 And 01

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

囚你心 2024-08-11 18:00:20

很简单,首先在流程任务中创建一个派生列组件。
然后,在组件中创建一个新列,将其命名为 MONTH_YEAR 并在表达式字段中输入:

 (DT_WSTR, 10)DATEPART(month, [YOUR_DATETIME_COLUMN]) +
 "_" + (DT_WSTR, 4)DATEPART(year, [YOUR_DATETIME_COLUMN])

然后,对于当天的片段,执行相同的操作,仅创建一个名为 DAY 的新列> 并从 DATEPART(..) 中取出当天的内容。

由于您将这些创建为新列,因此您可以根据需要在数据流中使用它们。

Simple, first create a Derived Column component in your flow task.
Then, in the component, create a new column, call it MONTH_YEAR and in the Expression field type:

 (DT_WSTR, 10)DATEPART(month, [YOUR_DATETIME_COLUMN]) +
 "_" + (DT_WSTR, 4)DATEPART(year, [YOUR_DATETIME_COLUMN])

Then for the day piece do the same thing only creating a new column called DAY and pull the day piece out from DATEPART(..).

Since you created those as new columns you can then use them in the data flow as wished.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文