I have a stored procedure like this;
我有这样的存储过程;
ALTER PROCEDURE [dbo].[crudValues]
@tblValue as dbo.tblValue READONLY
AS
BEGIN
SET NOCOUNT ON;
UPDATE Value SET Value.Value = @tblValue.Value, Value.LastUpdate = @tblValue.LastUpdate FROM Value INNER JOIN @tblValue ON Value.ID = @tblValue.ID
END
When i execute this stored procedure it gives me the error
当我执行这个存储过程时,它给了我错误
Msg 137, Level 16, State 1, Procedure crudValues, Line 21
Must declare the scalar variable "@tblValue".
Msg 137, Level 16, State 1, Procedure crudValues, Line 21
Must declare the scalar variable "@tblValue".
Msg 137, Level 16, State 1, Procedure crudValues, Line 21
Must declare the scalar variable "@tblValue".
How can i declare scalar table type. or how can i fix this error?
我如何声明标量表类型。或者我该如何解决这个错误?
2 个解决方案
#1
1
Either enclose the table variable in double-quotes or in brackets (but not in the join) or use an alias for the table variable in the query:
将表变量括在双引号或括号中(但不在连接中)或在查询中使用表变量的别名:
ALTER PROCEDURE [dbo].[crudValues]
@tblValue dbo.tblValue READONLY
AS
BEGIN
SET NOCOUNT ON;
UPDATE Value
SET Value.Value = t.Value, Value.LastUpdate = t.LastUpdate
FROM Value INNER JOIN @tblValue t ON Value.ID = t.ID
END
The alternatives with quoted identifiers would look like: [@tblValue].ID
or "@tblValue".ID
.
带引号标识符的备选方案如下所示:[@tllValue] .ID或“@tblValue”.ID。
#2
0
You need to alias the table. This code produces the same error:
您需要为表格添加别名。此代码产生相同的错误:
DECLARE @Table TABLE
(
Field INT
)
SELECT
@Table.Field
FROM @Table
#1
1
Either enclose the table variable in double-quotes or in brackets (but not in the join) or use an alias for the table variable in the query:
将表变量括在双引号或括号中(但不在连接中)或在查询中使用表变量的别名:
ALTER PROCEDURE [dbo].[crudValues]
@tblValue dbo.tblValue READONLY
AS
BEGIN
SET NOCOUNT ON;
UPDATE Value
SET Value.Value = t.Value, Value.LastUpdate = t.LastUpdate
FROM Value INNER JOIN @tblValue t ON Value.ID = t.ID
END
The alternatives with quoted identifiers would look like: [@tblValue].ID
or "@tblValue".ID
.
带引号标识符的备选方案如下所示:[@tllValue] .ID或“@tblValue”.ID。
#2
0
You need to alias the table. This code produces the same error:
您需要为表格添加别名。此代码产生相同的错误:
DECLARE @Table TABLE
(
Field INT
)
SELECT
@Table.Field
FROM @Table