Some times we need to create a stored
procedure where sometimes parameters are passed and sometimes not. If we create
a simple storedprocedure and we asked for parameter and not passed then it raise
error. So we do not need to make a big changes , just follow the given
instructions.
Create procedure your_procedure
@name
nvarchar(max)
as
begin
select
* from yourtable
where ename =@name
end
exec
your_procedure
now, here if we are not
passing the @name, it will raise error.
now try this..
create
procedure your_procedure
@name
nvarchar(max)=''
as
begin
select
* from yourtable
where ename =@name
end
Now if we run this stored procedure without
pasing parameter , it will not show the error.
exec your_procedure
just initialized the value at time of
declearation and fixed the error.