create proc proc_manager
@tablename varchar,
@strWhere varchar,
@count int output
as
begin
declare @strSql nvarchar(1000)
set @strSql='select @count=count(1) from '+@tablename+' where '+@strWhere
end
exec sp_executesql @strSql,N'@count int output',@count output
declare @sum int
exec proc_manager 'ask','id>0',@sum output
print @sum
错误:
消息 4145,级别 15,状态 1,第 1 行
在应使用条件的上下文(在 'i' 附近)中指定了非布尔类型的表达式。
------解决方案--------------------
alter proc proc_manager
@tablename varchar,
@strWhere varchar,
@count int output
as
begin
declare @strSql nvarchar(1000)
set @strSql='select '+CONVERT(VARCHAR(10),@count)+'=count(1) from '+@tablename+' where '+@strWhere
end
exec sp_executesql @strSql,N'@count int output',@count output
declare @sum int
exec proc_manager 'ask','id>0',@sum output
print @sum