我想将@inputData
设置为select语句的行,然后将其传递到我的DoSomething
存储过程中:
DECLARE @inputData [dbo].[TestTableType];
SET @inputData = (
SELECT
1 AS Client_Id,
20170202 AS a,
18595 AS b,
49.82 AS c,
88 AS d,
31 AS e,
0.67 AS f,
0 AS g,
44 AS h,
1827 AS i,
5 AS j,
87 AS k
);
EXEC DoSomething @inputData;
但是我收到了这个错误:
Msg 137,Level 16,State 1,Line 3
必须声明标量变量“@inputData”。
我做错了什么?
答案 0 :(得分:4)
你没有SET
个表变量。你INSERT
进入他们:
INSERT INTO @inputData /* Should have column list here also */
SELECT
1 AS Client_Id,
20170202 AS a,
18595 AS b,
49.82 AS c,
88 AS d,
31 AS e,
0.67 AS f,
0 AS g,
44 AS h,
1827 AS i,
5 AS j,
87 AS k
;
答案 1 :(得分:1)
尝试使用INSERT INTO。将表类型视为临时表(它基本上是)。
DECLARE @inputData AS TestTableType
INSERT INTO @inputData
SELECT
1 AS Client_Id,
20170202 AS a,
18595 AS b,
49.82 AS c,
88 AS d,
31 AS e,
0.67 AS f,
0 AS g,
44 AS h,
1827 AS i,
5 AS j,
87 AS k
);