Paramedterised Store Proceudre in SQL Server

-- Store Procedure

-- Store procedure is precompiled object in database

-- advantage of store procedure is

-- if you wnat to run some long query again and again so just take advantage of store procedure

-- eg wirte your long query into your procedure and run it into one line

 

Parameterized store procedure:

 

-- in store procedure with parameter means pass some value to get your answer

--eg. suppose you wnat data after entering date range that means you give two date to get you data.

 

--Note:

--Here @Name is variable and we have given data type varchar(10) to that variable

 

create procedure WelcomeMessage @Name varchar(10)

as

begin

select 'Hello '+ @name + ', How are you ' -- wirte your code over here

end

execute WelcomeMessage 'ashok' -- this is the way to run your proceudre

 

----------------------------------------------------------

 

--Ho update your procedure use keywork alter and update you code according to your requirement

 

alter procedure WelcomeMessage @Name varchar(10)

as

begin

select 'Hello '+ @name + ', How are you ' -- wirte your code over here

end

execute WelcomeMessage 'ashok' -- this is the way to run your proceudre