Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Optional parameters in stored procedure

Status
Not open for further replies.

ByzantianX

Programmer
Dec 18, 2000
103
I need to make a stored procedure on sql server which should look like this:

create sp1
@prm1 text, @prm2 int, @prm3 bit.... @prmN (any data type)
as
set no count on
update tbl
set fld1=@prm1
fld2=@prm2
.
.
.
fldN=@prmN
return

but the trick is that I need those parameters to be optional. So, if I pass some value to the parameter that the procedure do not update that particular field.Is there any elegant solution which exclude loop etc.?
Thank you in advance!
 
If I remember correctly, I believe you need to set them equal to something when you declare them, and then they become optional -- if they aren't passed, they take on the default values you have supplied...

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top