当前位置: 代码迷 >> Sql Server >> 查询条件作为参数并返回值的存储过程?解决办法
  详细解决方案

查询条件作为参数并返回值的存储过程?解决办法

热度:77   发布时间:2016-04-27 20:56:38.0
查询条件作为参数并返回值的存储过程?
create   procedure   sp_aa
(
@where   varchar(8000)= ' ',--条件
@sqlstr   varchar(8000)=null,
@total   varchar(50)   output
)
AS

set   @sqlstr= 'select   '[email protected]+ '=count(id)   from   aa   '[email protected]

exec(@sqlstr)

[email protected],表中有记录的

------解决方案--------------------
create procedure sp_aa
(
@where varchar(8000)= ' ',--条件
@sqlstr nvarchar(4000)=null,
@total varchar(50) output
)
AS

set @sqlstr= 'select @total=count(id) from sysobjects '[email protected]

exec sp_executesql @sqlstr,N '@total varchar(50) output ',@total output

declare @total varchar(50)
exec sp_aa ' ',NULL,@total output
print @total
  相关解决方案