Tuesday, 27 February 2018

Microsoft SQL Multi-Statement Table Valued Function

Microsoft SQL Multi-Statement Table Valued Function.

--Table structures are defined.
--unlike inline table valued function which do not define table structures.
--Updates cannot be performed on multi-statement table valued functions.
--unlike inline table valued functions which one can perform updates on.

create function returnMultiStatementTable()
returns @table table([Product] [varchar](50),
    [Low] [varchar](50),
    [High] [varchar](50),
    [Close] [varchar](50),
    [Previous] [varchar](50),
    [Direction] [varchar](50))
begin
insert into @table ([Product],[Low],[High],[Close],[Previous],[Direction])
select [Product],[Low],[High],[Close],[Previous],[Direction] FROM [test].[dbo].[options ftse]
return
end;


--write select statement to retrieve inserted rows.

select * from returnMultiStatementTable()

Inline image 1

No comments:

Post a Comment