我的要求是根据传递的id从存储过程返回用户定义的表。
首先,我将表格类型创建为:
CREATE TYPE test AS TABLE
(
id int not null,
name nvarchar(50) not null,
value nvarchar(50) not null
)
现在我将我的存储过程定义为:
CREATE PROCEDURE [dbo].sp_test
@id int,
@racun_stavke dbo.test READONLY -- I need this as OUTPUT ?
AS
BEGIN
SET NOCOUNT ON;
/*FILL MY OUTPUT Type Table AS I LIKE and return*/
//enter code here
END
答案 0 :(得分:1)
您可以创建用户定义的函数而不是存储过程。它很直接,在https://technet.microsoft.com/en-us/library/aa214485(v=sql.80).aspx
处得到了很好的解释示例:
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