0

I have a WHERE-clause in my SQL-query, and would like to add an argument depending on if the @Fran variable is set.

If @Fran is NULL, then it shouldn't filter the results at all. Otherwise, if @Fran is set, then it should add a WHERE clause "AND franid=@Fran". How could i do that?

0

2 Answers 2

3
SELECT ...
FROM ...
WHERE ...
AND ((@Fran IS NULL) OR (@Fran IS NOT NULL AND franid=@Fran));
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! Worked great!
0
AND IFNULL(@Fran, franid) = franid

results in TRUE if @Fran is NULL (then it is essentially franid = franid) and in @Fran = franid if it is not NULL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.