sql server - How to turn separate year, month and day columns into a single date? -


i have year column contains things 2013, 2012, etc. month column displays 1-12, , day column contains 1-31. need run select concatenates them , casts them actual date, unsure how go this. can provide input?

for sql server 2008+:

select convert(date,cast([year] varchar(4))+'-'+                     cast([month] varchar(2))+'-'+                     cast([day] varchar(2))) 

for sql server 2005:

select convert(datetime,cast([year] varchar(4))+                         right('00'+cast([month] varchar(2)),2)+                         right('00'+cast([day] varchar(2)),2)) 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -