Simon Cripps
asked on
SQL Where Like filter to show all when empty
I have a SQL command to display some recoreds in a GridView.
The view is filtered on the SQL command below:
SelectCommand="SELECT * FROM [ProductIncluded] WHERE ([GFMerchantProductName] LIKE '%' + @GFProductName2 + '%')">
Which works well when I populate @GFProductName2 with a value, however I would like to show all records if the @GFProductName2 is left blank, whereas it returns no records. How would I do this in the same SQL statement rather than a new SQLcommand for when @GFProductName2 is left blank.
The view is filtered on the SQL command below:
SelectCommand="SELECT * FROM [ProductIncluded] WHERE ([GFMerchantProductName] LIKE '%' + @GFProductName2 + '%')">
Which works well when I populate @GFProductName2 with a value, however I would like to show all records if the @GFProductName2 is left blank, whereas it returns no records. How would I do this in the same SQL statement rather than a new SQLcommand for when @GFProductName2 is left blank.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
simply add or GFProductName2 is null to where clause
ASKER
Does the job for the command.
ASKER