62,042
社区成员
发帖
与我相关
我的任务
分享
CREATE PROCEDURE usp_GetTotal
AS
DECLARE @counts int --临时记录查询结果有否有记录
DECLARE @sql nvarchar(500)
DECLARE @ParmDefinition nvarchar(500)
SET @sql = N'SELECT @counts=COUNT(*) from from JLZF_jg where cbdh=''TJ01'' and bh in (select bh from JLZF_jgT where zfqh <> 0 and zfqh =10)';
SET @ParmDefinition = N'@counts int OUTPUT';
EXECUTE sp_executesql @sql, @ParmDefinition, @counts OUTPUT;
IF @counts <>0
BEGIN
select round(sum(isnull(hdje,0)),0) as hdje from JLZF_jg where cbdh='TJ01' and bh in (select bh from JLZF_jgT where zfqh <> 0 and zfqh =10) group by left(dh,1)
END
ELSE
BEGIN
SELECT hdje=0
END
GO