Thursday, May 9, 2013

Converting this value from Varchar to Datetime in format of YYYY-MM-DD


insert [Scorecard].[Stage].[TMP1]

([Key]

,[MemberID]

,[PlanID]

,[ADDate]

,[HIDDate]

SELECT

[Key]

,[MemberID]

,[PlanID]

, case when [ADDate]<'2078-12-31' then [ADDate] else null end as ADDate

, case when [HIDDate]<'2078-12-31' then [HIDDate] else null end as HIDate

From Table1

My [Scorecard].[Stage].[TMP1] has data type varchar(10) for Fields [ADDate] and [HIDDate]. Intially these fields has value in format of "2012-09-05 10:27:00.000".


These 2 columns values I am getting it from another table named "Table Random".


when I am inserting into my destination table [Scorecard].[Stage].[TMP1], it comes as "Dec 31 201". I believe it is because the destination table data type is Varchar(10).


I want this value for those fields in format of YYYY-MM-DD


Thanks in advance. Any help will be appreciated.



No comments:

Post a Comment