SQL - Select all when filter value is empty

Posted by iansinke on Stack Overflow See other posts from Stack Overflow or by iansinke
Published on 2010-03-16T01:27:26Z Indexed on 2010/03/16 1:29 UTC
Read the original article Hit count: 313

Filed under:

I have a SQL query in my ASP.net web app that looks like this:

SELECT * FROM [Records] WHERE ([title] LIKE '%' + @title + '%')

@title, of course, is the value of a text box on the page.

My question is, why, when the text box is empty, does this return nothing? And how can I make it return everything, like logic tells me it ought to?

© Stack Overflow or respective owner

Related posts about sql