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