|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
return table type from functions
alter function SalesByStore (@storeid varchar(30))
returns table as begin declare @in varchar(50) declare @return_table table (id int, name varchar (50)) set @in = 'test' insert into @return_table (id, name) values (1, @in) select * from @return_table return (select * from @return_table) end -- I need to return the table of values. I tried to write a simple example. Now it is a code deduces a mistake. Help to understand. The table necessarily should content variables. It is possible? Thanks for attention. |
|
#2
|
|||
|
|||
|
it should be like this (the only thing missing from you was the decalaration of the fields for the table):
CREATE FUNCTION LargeOrderShippers ( @FreightParm money ) RETURNS @OrderShipperTab TABLE ( ShipperID int, ShipperName nvarchar(80), OrderID int, ShippedDate datetime, Freight money ) AS BEGIN INSERT @OrderShipperTab SELECT S.ShipperID, S.CompanyName, O.OrderID, O.ShippedDate, O.Freight FROM Shippers AS S INNER JOIN Orders AS O ON S.ShipperID = O.ShipVia WHERE O.Freight > @FreightParm RETURN END (try the book online on user-defined function..it's gold mine!) |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > return table type from functions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|