I am trying to make a query that does the following: I have columns in my Items database, and these columns are called Title, AuthorName and ItemType. I want to do the following in my query: User enters AuthorName, Title and selects ItemType from the dropdown list. User may leave AuthorName or Title boxes empty. Even if he for example does not fill AuthorName part, if an item is found with specified ItemType and specified Title i show it in results. Similarly Title may be left empty, in this case the item with the specified AuthorName is listed in results list. Here is my query:
SELECT *
FROM [Items]
WHERE ( ( ( [Title] LIKE '%' + @Title + '%' )
AND ( [ItemType] = @ItemType )
)
OR ( ( [AuthorName] LIKE '%' + @AuthorName + '%' )
AND ( [ItemType] = @ItemType )
)
)
But when AuthorName or Title is left empty, no results are found. Can anyone help?
Thanks