Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

create procedure prcDept

as
begin
select name from [HumanResources].[Department]
end

exec prcDept

alter procedure prcDept


as
begin
select [DepartmentID],name from [HumanResources].[Department]
end
exec prcDept
=========================================

CREATE PROCEDURE SelectAllCustomers @City nvarchar(30)


AS
SELECT city FROM [Person].[Address] WHERE City = @City

exec SelectAllCustomers 'Verrieres Le Buisson'

select city from [Person].[Address]


=======================================================

drop procedure GetImmediateManager

CREATE PROCEDURE GetImmediateManager


@BusinessEntityID INT,
@JobTitle nvarchar(50) OUTPUT
AS
BEGIN
SELECT @JobTitle=JobTitle
FROM HumanResources.Employee
WHERE BusinessEntityID = @BusinessEntityID
END

---executing parameterized procedure having output parameter

DECLARE @JobTitle nvarchar(50)


exec GetImmediateManager 2, @JobTitle OUTPUT
print @JobTitle
======================================================

calling one procedure from another procedure

create procedure Sp_insert


(

@ID int ,

@TempName varchar(max)

as
begin

Declare @SampleTable Table(id int, Name varchar(max))

Insert into @SampleTable(id,Name)values(@ID,@TempName)

select*from @SampleTable

end

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

create procedure Sp_Call

@SID int,

@Name varchar(max)

as

begin

exec Sp_insert @ID=@SID,@TempName=@Name

end

Exec Sp_Call @SID=1,@Name='Arun'


====================================================
create function [HumanResources].rohan
(@Rate money)
returns money
as
begin
return (@Rate*8*30)
end
---calling function
declare @Rate money
set @Rate = [HumanResources].rohan (12.25)
print @Rate
============================================

You might also like