views:

35

answers:

2

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

I have a store procedure with 3 input parameter 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 sp 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  A: 

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

Martin Smith
A: 

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.

Sachin Shanbhag

related questions