Link to home
Start Free TrialLog in
Avatar of Simon Cripps
Simon CrippsFlag for United Kingdom of Great Britain and Northern Ireland

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.
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Simon Cripps

ASKER

Thanks this works fine when running a standalone SQL query. however is not working against the gridview. I suspect that @GFProductName2 is not returning a NULL value despite being empty, I have tried trim, do you know a method to set to null if empty.
Avatar of js-profi
js-profi

simply add    or GFProductName2 is null       to where clause
Does the job for the command.