将 table 类型参数与常规参数一起使用
Using table type parameter together with regular parameter
我想用一些附加参数将一些列表插入 SQL 服务器 table。像这样
CREATE PROCEDURE SP_AddChosenSecurities
@ProjectID INT,
@Securities BusinessValuationSecurityTblType READONLY
AS
BEGIN
INSERT INTO TblBusinessValuationsSecurities @ProjectID, @Securities
END
BusinessValuationSecurityTblType
是一个 table 类型的参数
我该怎么做。
谢谢!
因为你的第二个参数是table-valued参数,你需要select从它喜欢来自常规 table - 像这样:
CREATE PROCEDURE SP_AddChosenSecurities
@ProjectID INT,
@Securities BusinessValuationSecurityTblType READONLY
AS
BEGIN
INSERT INTO TblBusinessValuationsSecurities
SELECT @ProjectID, Col1, Col2, Col3
FROM @Securities
END
假设您的 table 值参数中有 Col1, Col2, Col3
,请根据需要进行调整。
旁注:您应该 NEVER 为您的存储过程使用 sp_
前缀。微软有 reserved that prefix for its own use (see Naming Stored Procedures), and you do run the risk of a name clash sometime in the future. It's also bad for your stored procedure performance。最好只是简单地避免 sp_
并使用其他东西作为前缀 - 或者根本没有前缀!
我想用一些附加参数将一些列表插入 SQL 服务器 table。像这样
CREATE PROCEDURE SP_AddChosenSecurities
@ProjectID INT,
@Securities BusinessValuationSecurityTblType READONLY
AS
BEGIN
INSERT INTO TblBusinessValuationsSecurities @ProjectID, @Securities
END
BusinessValuationSecurityTblType
是一个 table 类型的参数
我该怎么做。
谢谢!
因为你的第二个参数是table-valued参数,你需要select从它喜欢来自常规 table - 像这样:
CREATE PROCEDURE SP_AddChosenSecurities
@ProjectID INT,
@Securities BusinessValuationSecurityTblType READONLY
AS
BEGIN
INSERT INTO TblBusinessValuationsSecurities
SELECT @ProjectID, Col1, Col2, Col3
FROM @Securities
END
假设您的 table 值参数中有 Col1, Col2, Col3
,请根据需要进行调整。
旁注:您应该 NEVER 为您的存储过程使用 sp_
前缀。微软有 reserved that prefix for its own use (see Naming Stored Procedures), and you do run the risk of a name clash sometime in the future. It's also bad for your stored procedure performance。最好只是简单地避免 sp_
并使用其他东西作为前缀 - 或者根本没有前缀!