CREATE PROCEDURE [lot].[wipeAll]
@num VARCHAR(16),
@quotaType INT,
@TableName NVARCHAR(128)
AS
BEGIN
SET NOCOUNT ON;
DELETE FROM @TableName WITH (TABLOCKX)
WHERE num = @num AND quotaType = @quotaType;
END
我不知道如何解决此错误
上面的代码段中的Tablockx附近的语法不正确。期待'('或选择
。任何帮助将不胜感激!
答案 0 :(得分:0)
您需要为此使用动态SQL:
BEGIN
SET NOCOUNT ON;
DECLARE @sql NVARCHAR(MAX);
SET @sql = '
DELETE FROM @TableName WITH (TABLOCKX) WHERE num=@num AND quotaType=@quotaType)';
SET @sql = REPLACE(@sql, '@TableName', @TableName);
EXEC sp_executesql @sql,
'@num varchar(16), @quotaType int',
@num=@num, @quotaType=quotaType
END;