I'm writing an 'advanced search' page for a web application. It basically has a form that goes:
Search for query in the forum forum name posted by username in the last date
The idea is that users can leave fields blank if they wish and the search won't include it.
I'd rather not write a stored procedure for searching based on every possible combination of leaving values blank. Is there a way I can write a stored procedure so that the search changes based on which parameters passed in are blank?
Something like (pseudo code)
SELECT * FROM Table WHERE Message = @query
(if @username isn't null)
AND Username = @Username
(if @forum isn't null)
AND Forum = @forum
..and so on.
Thanks for any help you can provide!