Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CASE Statement 1

Status
Not open for further replies.

dscoiho

MIS
Joined
Sep 26, 2005
Messages
51
Location
US
Does anyone have an idea on either better way to write the statement below or why I cant use "TO" for then results?

Trade Month field is a number between 1 and 12 and I cant use the date field in our tables due to certain limitations.

TRADE_MONTH=(CASE WHEN DATEPART(MONTH,GETDATE()) = 1 THEN 1 to 12 ELSE 1 to DATEPART(MONTH,GETDATE())-1 END)

Thanks in advanced.
 
I believe you want something like this. You need to put any 'hard coded' varchar values between apostrophies, and convert the datepart to varchar so that you can

Code:
TRADE_MONTH= CASE WHEN DATEPART(MONTH,GETDATE()) = 1 
THEN '1 to 12' 
ELSE '1 to ' + cast(DATEPART(MONTH,GETDATE())-1 as varchar) 
END

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top