i have a procedure in which the below condition is to be written in a WHERE clause. How do I do that.
itemid is a parameter which can be null.
if itemid is available then add it to my where clause,else do nothing
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Some people use this technique
It guarantees though that you will never get an index seek on the itemid column.
A better approach if the table is at all big is to split the query up into 2 separate cases
If the number of combinations is too large you can consider dynamic SQL. Be sure you understand SQL injection first.
Ref: Dynamic Search Conditions in T-SQL