存储过程:将 varchar 值 'select ' 转换为数据类型为 int 的列时发生语法错误怎么处理
CREATE PROCEDURE GetOrderBy@ParentID int,
@Resultval int output,
@TableName varchar(200)
AS
begin
declare @strSQL nvarchar(1000)
SET @strSQL = ‘select ’+@Resultval+‘ = count(*) from ['+@TableName+'] where ParentID =’+ @ParentID
exec(@strSQL)
end
GO
运行提示:将 varchar 值 'select ' 转换为数据类型为 int 的列时发生语法错误
我把 SET @strSQL = ‘select ’+@Resultval+‘ = count(*) from ['+@TableName+'] where ParentID =’+ @ParentID 改为
SET @strSQL = N'select @Resultval = count(*) from ['+@TableName+'] where ParentID = @ParentID'
却又提示 要声明 @Resultval
这要怎么处理????