日期:2014-05-17  浏览次数:20443 次

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)