Create FUNCTION GetEmployee()
RETURNS @rtnTable TABLE
(
— columns returned by the function
ID UNIQUEIDENTIFIER NOT NULL,
Name nvarchar(255) NOT NULL
)
AS
BEGIN
DECLARE @myTable table (id uniqueidentifier, name nvarchar(255))
insert into @myTable
select from your stuff
–This select returns data
insert into @rtnTable
SELECT ID, name FROM @myTable
return
END
you can’t access Temporary Tables from within a SQL Function. You will need to use table variables so essentially. After select the value to return it as table formate you have to insert the selected records to ‘@rtnTable’ which returns in table structure.