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 |
|
donnapep
Starting Member
15 Posts |
Posted - 2005-03-30 : 09:47:24
|
| Hello,Here is the where clause of my query:WHERE dl.rqscde = 'CMP' AND dl.dstctl = '0000285' AND(dl.actcde = 'INS' OR (dl.actcde = 'ADD' AND dl.dstctl <> (SELECT DISTINCT(dl.dstctl) FROM acmsctl/dstlog dl... WHERE dl.rqscde = 'CMP' AND dl.dstctl = '0000285' AND dl.actcde = 'INS')))What I am essentially trying to do here is find all rows where actcde = 'INS'. If there are no such rows, only then do I want to return those rows where actcde = 'ADD'. So my subquery is basically to determine if there are any rows where actcde = 'INS'.The query works for the 'INS' records, however, 'ADD' records are not being returned. I'm assuming this is because, in this case, my subquery doesn't return anything. How can I fix this?Any help is appreciated.Thx. |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2005-03-30 : 09:56:56
|
| Hmm. You'd need something that does a count and then make your comparison based on that. Whether it's a good idea for that to be a subquery I don't know.SELECT blah FROM blah where actcde = 'INS' or ((SELECT count(actcde) WHERE actcde = 'INS') = 0 and actcde = 'ADD')But i am not sure that you have exactly said what you want to do.-------Moo. :) |
 |
|
|
donnapep
Starting Member
15 Posts |
Posted - 2005-03-30 : 11:12:26
|
| Thanks. That is a really neat solution that did the trick. I never would have thought of that (probably because I'm not that creative. :) |
 |
|
|
|
|
|