Monday, February 13, 2012

% Wildcard Include Nulls

I have a query with 4 parameters:

Name

Location

Employee Number

Officer Code

There are no null values in Name, location and Employee Number. However, all employees do not have an officer code. So in my query I use a where clause that says WHERE OfficerCode LIKE'%'+@.Param4+'%'. I use a % for the default value in my ASP.net data control. The only problem is that the only records returned have non-null values in the OfficerCode field. How can I use a wildcard for a default value and return all records (null and non-null)?

OR OfficerCode IS NULL

No comments:

Post a Comment