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.Contac tID, ContactType,
CASE WHEN Contacts.Contac tType = 0
THEN Contacts.Compan yName
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(CompanyNam e,1) END)
Any help is appreciated,
LQ
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.Contac tID, ContactType,
CASE WHEN Contacts.Contac tType = 0
THEN Contacts.Compan yName
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(CompanyNam e,1) END)
Any help is appreciated,
LQ
Comment