Sql server Function Returning a table

1
21

here is an example for Functions in SQl Server which returns a table

–<START>
create function fnTab()
returns
@tab table(
f1 int,f2 varchar(2000)
)
as
begin

–inserting values to the table to be returned
insert into @tab values (1,’name1′)
insert into @tab values (1,’name2′)
return
end
–</END>

now select from function

select * from dbo.fnTab()

Result

f1 f2
1 name1
1 name2

(2 row(s) affected)

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here