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 |
|
jcb267
Constraint Violating Yak Guru
291 Posts |
Posted - 2011-02-28 : 12:45:32
|
| Can anyone help me to write a nested case statement? Is a nested case statement what I need?This is what I have, it produces blanks though:case when (pb.sid) not in ('100002', '100003', '100360') then (sd.pr)when (pb.sid)in ('100002', '100003', '100360') then (md.pr)when (sd.pr) = '' then 'Unknown' when (md.pr) = '' then 'Unknown' endas Region |
|
|
sunitabeck
Master Smack Fu Yak Hacker
5155 Posts |
Posted - 2011-02-28 : 14:53:08
|
| The way you have written this, it is not nested. It is almost exactly like the switch statement in C# or Java. Hard to say what you should be using without some sample data and examples of what you are expecting the output to be.Also, what is the data type of sd.pr and md.pr? Might be a good idea provide the data types as well. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-03-03 : 09:47:08
|
| See what happens when do thiscase when (pb.sid) not in ('100002', '100003', '100360') then (sd.pr)when (pb.sid)in ('100002', '100003', '100360') then (md.pr)when ((sd.pr) = '' or sd.pr is null) then 'Unknown' when ((md.pr) = '' or md.pr is null) then 'Unknown' endas RegionMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|