SQL - Change decimals to date

For some reason, instead of having a date field in my data, I have three separate fields:

Year
Month
Day

All are decimals. Year is 4 digits, month and day are 2 digits each. How do I convert this into a date and/or filter all the data on a range of dates?
eddie736Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
select dateadd(month, month_col - 1, dateadd(day, day_col - 1, convert(datetime, cast(year_col as varchar(4)) + '01-01', 120)))
  from yourtable
0
plusone3055Commented:
output

#dateformat (varaible,  'yyyy-mm-dd')#
0
plusone3055Commented:
<--- Bows to Angell III the god of EE :)

0
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

eddie736Author Commented:
Hi angell:

I received this error when I used your soloution:

Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
then you have year_col value < 1900, or null ...
0
eddie736Author Commented:
The years don't appear to have nulls or <1900s, but the days and months have one digit where <10. Would that be the problem?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sorry, actually my fault. I omitted a "-"
select dateadd(month, month_col - 1, dateadd(day, day_col - 1, convert(datetime, cast(year_col as varchar(4)) + '-01-01', 120)))
  from yourtable

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eddie736Author Commented:
Perfect!! Thanks!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.