问题:两个存储过程都返回一个int值,但两个int值之和返回默认值0
我已经看到了选择有效或使用临时表的各种解决方案,但没有问题,但我需要将结果分开保存,然后在末尾加总。(允许sp模块化)保持2008兼容性的任何想法?
主要思想是拥有一个具有总结果的父sp,以及几个模块化子sp,每个子sp是其自己的结果,供父使用。
How to assign an exec result to a sql variable?
declare @Result1 int = 0,
@Result2 int = 0,
@Total int = 0,
@projectID int,
@periodID int
exec @Result1 = [dbo].[QSP_getCount1] @projectID = 1,
@periodID = 12
exec @Result2= [dbo].[QSP_getCount2] @projectID = 1,
@periodID = 12
set @Total = @Result1 + @Result2
select @Total
存储过程-两者都是相同的,只是使用差异表(返回值为1、15)
if OBJECT_ID('dbo.QSP_getCount1', 'P') is not null
drop procedure [dbo].[QSP_getCount1]
go
create procedure [dbo].[QSP_getCount1] @projectID int,
@periodID int
as
declare @NullTotal int = 0;
select @NullTotal = case when col1 is not null then @NullTotal + 1 else @NullTotal end,
@NullTotal = case when col2 is not null then @NullTotal + 1 else @NullTotal end,
@NullTotal = case when col3 is not null then @NullTotal + 1 else @NullTotal end,
@NullTotal = case when col4 is not null then @NullTotal + 1 else @NullTotal end,
@NullTotal = case when col5 is not null then @NullTotal + 1 else @NullTotal end
from tablename
where projectID = 1005 and periodID = 210
select @NullTotal
答案 0 :(得分:3)
procs中没有RETURN
statement,默认返回值为0。使用RETURN @NullTotal
代替select @NullTotal
返回int
值。 proc中的SELECT
返回结果集(在这种情况下,包含1行,在此为1列),而不是标量。
答案 1 :(得分:1)
代码中有错误
pd.concat([df, tmp]).groupby('date', as_index=False)["Anomaly"].sum()
date Anomaly
0 2018-12-06 0
1 2019-01-07 1
2 2019-02-06 1
3 2019-03-06 0
4 2019-04-06 0
@ Result1被声明两次