当前位置: 代码迷 >> Sql Server >> sql server 过程获取值有关问题
  详细解决方案

sql server 过程获取值有关问题

热度:64   发布时间:2016-04-24 23:28:24.0
sql server 过程获取值问题
select @Sum= sum(Totalpay) from bcs_Sale;
if @strWhere <> ''
begin
    exec('select @Sum=sum(Totalpay) from bcs_Sale where '+@strWhere);
end


执行后报错:
消息 137,级别 15,状态 1,第 1 行
必须声明变量 '@Sum'。

------解决方案--------------------
declare @NStatement nvarchar(max)
declare @count int
set @NStatement='select @count=count(*) from ix_spc_planogram'
Exec sp_ExecuteSQL @NStatement, 
N'@count int output ', 
@count output

select @count

------解决方案--------------------
declare @sum  decimal(28,10)
  相关解决方案