Dealing with a null parameter in SP I have a stored procedure as a recordsource from a contacts table. In
this example, users can enter parameters to limit contacts by first
letter of last name or company name or keywords:
Example:
@myName nvarchar(30) = null,
@Alpha char(1) = null
SELECT
Contacts.ContactID, ContactType,
CASE WHEN Contacts.ContactType = 0
THEN Contacts.CompanyName
ELSE
isNull(Contacts.LastName,'?') + ', ' +
isNull(Contacts.FirstName,'?')
END
AS CNAME
FROM
Contacts
WHERE
(Keywords Like '%' + @myKeyword + '%' OR @myKeyword is Null)
So far, so good, but...
The problem is I want to also give the user the option of filtering
alphabetically by first letter. I can't figure out how to deal with
nulls in this example (user doesn't enter anything as parameter
@Alpha):
AND
(@Alpha = CASE ContactType WHEN 0 THEN Left(LastName,1) END
OR
@Alpha = CASE ContactType WHEN 1 THEN Left(CompanyName,1) END)
Any help is appreciated,
LQ |