Sunday, March 25, 2012

Cleaning up hardcode sections

Hey,

Does anyone know of a neat and easy way to modify this section of hardcode:

SELECT CASE dbo.requestsbyyeartemp.themonth when '1' then 'January' when '2' then 'Febuary' when '3' then 'March'
when '4' then 'April' when '5' then 'May' when '6' then 'June' when '7' then 'July' when '8' then 'August'
when '9' then 'September' when '10' then 'October' when '11' then 'November' when '12' then 'December' end as 'themonth', etc...

Requestsbyyeartemp is a table where the numbers corresponding to the months are stored. This statement is used to make a new table where the months are stored with the proper names and not numbers.

I would sooner not have any hardcode at all if there is a simple way to do it.

ThanksSELECT DATENAME(month, dbo.requestsbyyeartemp.themonth) AS 'themonth'|||Would this work if the <date> portion of DATENAME(<datepart>, <date>) is only a single number?

I ask this because I keep getting January no matter what number 'themonth' is?|||Any more suggestions anyone?|||How about:SELECT DateName(month, DateAdd(month
, dbo.requestsbyyeartemp.themonth, '1950-12-01')) AS themonth-PatP

No comments:

Post a Comment