Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-02-18 : 23:52:53
|
| Snehal writes "Hi,I have come across a situation, where i need to use CASE within CASE. I read the manual, as suggested, reviewed some sites. Couldn't find any help. Is NESTED CASE possible ?How can I use it ?sum(CASE WHEN (t1.yr=@year AND t1.month = ( case when @month = 1 then 12 else @month -1 END ) THEN amt ELSE 0 END)Here if i have month = 1 from an argument, then for the previous month, I want to go to December and previous year, let's say 2002. So, first I tried setting up month but I get stuck.Can anyone suggest any idea?Thanks,Snehal" |
|
|
LarsG
Constraint Violating Yak Guru
284 Posts |
Posted - 2003-02-19 : 07:59:27
|
| Apart from the missing ) before the second then I don't see any problem.sum(CASE WHEN (t1.yr=@year AND t1.month = ( case when @month = 1 then 12 else @month -1 END ) ) THEN amt ELSE 0 END) |
 |
|
|
|
|
|