Thursday, August 30, 2012

Convert the year, month and day column as date format

Below is the script to convert the year, month and day column as date format


SELECT
CAST(
CAST(year AS VARCHAR(4)) +
RIGHT('0' + CAST(month AS VARCHAR(2)),2) +
RIGHT('0' + CAST(day AS VARCHAR(2)),2)
AS DATE )
FROM [dbo].[SampleTable]

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.