Datime from Source into Month_Year and Day Column

  • This is my SSIS exercise

    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

    2. Destination Column:

    Month_Year Day

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

  • Without looking, I believe you will have to use the Convert Task, and then use the built in function to pull year() and Month() from the date column.

    Fraggle.

  • What is the reason to keep a Month and a Year in one column? I am just curious.

    It is easy to work if you divide your [DATETIME] as YEAR, MONTH, DAY columns.

    In this case

    YEAR is YEAR([DATETIME]) AS [Year]

    MONTH is MONTH([DATETIME]) AS [Month]

    DAY is DAY([DATETIME]) AS [Day]

  • Of course you can combine MONTH and YEAR in one column like that:

    MONTH_YEAR is (MONTH([DATETIME]) + '-' + YEAR([DATETIME])) AS [Month_Year]

  • Sergey Vavinskiy (9/20/2009)


    What is the reason to keep a Month and a Year in one column? I am just curious.

    It is easy to work if you divide your [DATETIME] as YEAR, MONTH, DAY columns.

    In this case

    YEAR is YEAR([DATETIME]) AS [Year]

    MONTH is MONTH([DATETIME]) AS [Month]

    DAY is DAY([DATETIME]) AS [Day]

    If you must do it via SSIS and not simply with the sql of your datasource that ssis uses (see above), you can use the exact same syntax as above, adding two new derived columns via the Derived Column Transformation editor in a ssis Data Flow.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply