Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi..
I am new to asp.net and ms sql.
so, please help me.
My question is how to exclude fileds in stored procedures. it means, for example i have to pass 5 fields to stored procedure, but i want to pass only 3 fields, remaining fields are leave.
if do like the stored procedures give error "like some field is expected some value".
please any one can help me.

(resume searching in monsterindia, we may pass some values only. remaining fields are leave empty,still the result will come without errors..... so, i want like this type of query please help me)
Posted

1 solution

Use default value for the parameter which you want to be passed as optional in stored procedure

like

create proc [SP_Name]
@var1 datatype -- must be passed
@var2 datatype -- must be passed
@var3 = NULL or Default value which you want -- either you pass it or leave it
@var4 = NULL or Default value which you want -- either you pass it or leave it
As
Begin

-- logic to select the result based on parameter values
if(@var3 is not null and @var4 is not null)
begin
end
else if(@var3 is null and @var4 is not null)
begin
end
else if(@var3 is null and @var4 is null)
begin
end


End
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900