Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Derived Column replace column

Status
Not open for further replies.

nc297

Programmer
Apr 7, 2010
162
US
In my table (T16) I have a column called FLG_CDT char(8) so the date in that column appears as 20100930

I want to change the date to appear as 9/30/2010 12:00:00 AM

I've added a Data Flow Derived column

In the Derived Column I selected replace FLG_CDT

What do I put in the Expression field and, it won't allow me to change the datatype. What am I doing wrong?
 
Here's one way. There may be a better way, but this works:
Code:
DECLARE @Dat VARCHAR(8);
SET @Dat = '07041776'
SELECT CAST(LEFT(@Dat, 2) + '/' + SUBSTRING(@Dat, 3, 2) + '/' + RIGHT(@Dat, 4) AS DATETIME);

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
oops... noticed as i hit submit, i had the string date out of order:
Code:
DECLARE @Dat VARCHAR(8);
SET @Dat = '17760704'
SELECT CAST(RIGHT(@Dat, 2) + '/' + SUBSTRING(@Dat, 5, 2) + '/' + LEFT(@Dat, 4) AS DATETIME);

--------------------------------------------------
“Crash programs fail because they are based on the theory that, with nine women pregnant, you can get a baby a month.” --Wernher von Braun
--------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top