Function returning Tables in SQL
Create Table DeptmentMaster
(
DID int PRIMARY KEY identity(1,1),
Dname varchar(25),
Lname varchar(25)
)
GO
Create Table EmMaster
(EID int identity(1,1),
DID int FOREIGN KEY REFERENCES DeptmentMaster(DID),
Fname varchar(25),
Lname varchar(25)
)
GO
INSERT INTO DeptmentMaster VALUES('ID','Solution')
INSERT INTO DeptmentMaster VALUES('Admin','Solution')
SELECT * FROM DeptmentMaster
SELECT * FROM EmMaster
INSERT INTO EmMaster VALUES (1,'Raj','Verma')
INSERT INTO EmMaster VALUES (1,'Shaily','Rana')
INSERT INTO EmMaster VALUES (2,'Anuj','Mohan')
create function DemoFunction(@EID int)
Returns Table
as
RETURN (Select em.FName ,Dm.DName from DeptmentMaster Dm INNER JOIN EmMaster Em ON Dm.DID = Em.DID
where Em.EID =@EID )
select * from DemoFunction(1)
Function returning Tables in SQL
Reviewed by Rupesh
on
05:54
Rating:
No comments: