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 |
|
db_sysadmin
Starting Member
27 Posts |
Posted - 2005-12-22 : 10:35:05
|
| Hey there guys,I have a CASE statement in a query, and I only want to count WHEN true conditions, don't want to count CASE ELSE statements... if I haveField = CASE WHEN Count.... WHEN Count...ENDELSE Others END /* IF I USE THIS STATMENT I get an extra row with the records that don't match any of the WHEN Statements.*/I.E: OTHERS 40If I just END it right there...I getI.E: NULL 40.I don't want either of them OTHERS NOR NULL there.What's wrong?Thanks in Advance... |
|
|
infobox
Starting Member
3 Posts |
Posted - 2005-12-22 : 10:48:39
|
| Nothing is wrong. If the ELSE argument is omitted and no comparison operation evaluates to TRUE, CASE returns NULL.One thing that can be done to get what you want is....Put a WHERE condition in your query for not allowing records having values other than those you have given in CASE WHEN statements.-Chintan. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-12-23 : 01:00:18
|
| Post some sample data and the result you wantMadhivananFailing to plan is Planning to fail |
 |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2005-12-23 : 06:06:28
|
| Indeed. Infobox is right though, you can't just ignore the data that doesn't match to a case, you either match it, or it returns NULL. If you want to remove it from the results, then you need to filter out the data with a WHERE condition.-------Moo. :) |
 |
|
|
|
|
|