Different approaches for calling procedure

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 330
create procedure spsampleWith2Params 
( @department_id integer, @sal decimal(9,2), @Name VARCHAR(100) = '%%' )
AS
Begin
select *
from EMPLOYEE
where DEPTID = @department_id
AND SALARY > @sal
AND EMPNAME like @Name;
End




-- Normal exceution
exec spsampleWith2Params 30, 5000, '%nn%';

-- @Name param is optional, So we can ignore the 3rd input for SP execution
exec spsampleWith2Params @sal=5000, @department_id=30;

-- Here, @param names are specified for more readability and understandability
exec spsampleWith2Params @department_id=30, @sal=5000, @Name='%nn%';

-- The Order of Input params is differed here
exec spsampleWith2Params @sal=5000, @department_id=30, @Name='%nn%';

Comments or Responses

Login to post response