Thursday, March 22, 2012

Computed Column "smalldatetime" from 3 separate columns?

I am currently storing:

ReportMonth As tinyint
ReportDay As tinyint
ReportYear As tinyint

in my table. Client software requires that I have a "smalldatetime" column, which contains the date. I'd like to base it off the current 3 columns I have (seeing as how I have months worth of data)

I tried the following formula, as well as variations thereof:

(convert(smalldatetime, ReportYear + "-" + ReportMonth + "-" + ReportYear))

What is the correct formula for performing the calculation? I can't seem to get it.

Thanks for your help!You'd rather try:

convert(smalldatetime, convert(nvarchar,@.ReportMonth) + N"-" + convert(nvarchar, @.ReportDay + N"-" + convert(nvarchar,@.ReportYear))

Originally posted by odinsdream
I am currently storing:

ReportMonth As tinyint
ReportDay As tinyint
ReportYear As tinyint

in my table. Client software requires that I have a "smalldatetime" column, which contains the date. I'd like to base it off the current 3 columns I have (seeing as how I have months worth of data)

I tried the following formula, as well as variations thereof:

(convert(smalldatetime, ReportYear + "-" + ReportMonth + "-" + ReportYear))

What is the correct formula for performing the calculation? I can't seem to get it.

Thanks for your help!

No comments:

Post a Comment