语句被终止。完成执行语句前已用完最大递归 100。 警告: 聚合或其他 SET 操作消除 如下存储过程 ,当执行时候,数据量只有几行的时候可以,几十行的时候就报错了,求高手指正,谢谢。
ALTER PROCEDURE [dbo].[cpzaocx]
@bs int
AS
BEGIN
with ctetemp as
(
select isnull(a.riqi,b.riqi) as riqi,isnull(jin,0) as jin,isnull(xiao,0) as xiao,
isnull(jin,0)-isnull(xiao,0) as cun
from
(
select CONVERT(char(10),pickuptime ,121) as riqi,sum(shul) as jin
from fitjujube
group by CONVERT(char(10),pickuptime ,121) ) a
full join
(
select CONVERT(char(10), fahuoriqi ,121) as riqi,
sum(b.shuliang) as xiao
from dbo.orderform a left join dbo.orderformchanpin b
on a.orderbianhao=b.orderbianhao where a.fahuoriqi is not null
group by CONVERT(char(10), fahuoriqi ,121)
) b on a.riqi=b.riqi)
--select * from ctetemp
, cte AS
(
SELECT ROW_NUMBER()OVER(ORDER BY riqi )id,riqi ,jin ,xiao ,jin-xiao AS cun
FROM ctetemp
),
test AS
(
SELECT * FROM cte WHERE id=1
UNION ALL
SELECT b.id,b.riqi,b.jin,b.xiao,a.cun+b.cun FROM test a INNER JOIN cte b ON a.id+1=b.id
)
SELECT a.id as id,a.riqi as 日期,a.jin as 进,a.xiao as 销,a.cun as 存,b.notes as 备注 FROM test a
left join ( select CONVERT(char(10),riqi ,121) as riqi,notes,pingzhong from dbo.kucunnote b where b.leibie='成品' and (pingzhong='' or pingzhong is null)) b on a.riqi=b.riqi
order by a.id desc