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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Separating Nulls & Values

Status
Not open for further replies.

dBjason

Programmer
Mar 25, 2005
355
US

I have the following query:

select b.Const
from ltrCompState as a, ltrConst as b
where a.LetterID = 3 and a.StateID = 2 and (a.CompID = 20 or a.CompID is null)
and b.CSID = a.CSID

Works *almost* great. The problem I have is this: It returns two records (which it should). I have to modify this and place it in a stored procedure which will have parameters for the LetterID, StateID and CompID values (@3, @2 and @20).

In this case there are two records, one has a CompID of 20 and the other record has a null CompID. In this (and every) case, I'd like it to only return one record.

CompID is only partially populated in the table. I'd like to get something like this:

If there's a record with a CompID of 20, return it (and only it)
If there's no matching CompID, give me the record with the null.

Any ideas?

Thanks,
Jason
 
Nevermind -- Created an SP with an IF...ELSE and SELECT COUNT.

Sorry!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top