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: 5

No comments:

All Rights Reserved by Technology from Developers Eye © 2014 - 2015
Powered By Blogger, Designed by Aadics
Disclaimers:: The information provided within this blogsite is for general informational purposes only. While we try to keep the information up-to-date and correct, there are no representations or warranties, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the information, products, services, or related graphics contained in this blogsite for any purpose.The author does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause.

Contact Form

Name

Email *

Message *

Powered by Blogger.