0

What is the best method of handling null parameters in stored procedure ?

I have a stored procedure with 3 input parameters, any one of them parameter can be null so how to handle those parameter.

SP_GetDetails input parameter (varchar p1, varchar p2, int p3, datetime p4, datetime p5)

In the stored procedure, there are different query based on input parameters.

if(p1<>null)
///
else
 if(p2<>null)
 ///
 else
  if()... so on...

So my question: Is it good to have n number of if condition.

1
  • 1
    Please provide an example. The information in this question is insufficient. Commented Oct 19, 2010 at 10:50

2 Answers 2

1

Your question is missing a lot of detail. I suspect this might be of help though. Dynamic Search Conditions in T-SQL

Sign up to request clarification or add additional context in comments.

Comments

0

The using of multiple If statements in stored procs detract from the readability of the code. Also, the maintainability of the code suffers. Instead you can use CASE statements.

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.