[数据处理] sqlserver 存储过程中有insert或者update 报错

squall0828铂金一 显示全部楼层 发表于 2022-6-9 11:26:23 |阅读模式 打印 上一主题 下一主题
当存错过程过程中有update 或者insert 语句操作时,存储过程就会出现执行SQL失败:“结果集无返回值,请至少输入一个输出参数”
回复

使用道具 举报

精彩评论7

yhdata_yzm 显示全部楼层 发表于 2022-6-9 11:34:08
截图看看你的语句呢
回复

使用道具 举报

squall0828铂金一 显示全部楼层 发表于 2022-6-9 13:34:09
ALTER proc [dbo].[qy_ttt]
as

select  convert(date,日期,120) as 日期,substring(别名,1,4)+RIGHT('00' + CONVERT(VARCHAR, substring(别名,5,2)), 2) as 别名 ,convert(nvarchar(100),类型) as 类型, convert( decimal(28,4),sum(case when 班次='白班' then 数量 else 0 end )) as 白班, convert(decimal(28,4),sum(case when 班次='晚班' then 数量 else 0 end ))as 夜班
into  #tempabc
from (
select  日期,别名,班次,(case substring(数量类型,1,1) when 1 then '1实际产能' when 2 then  '2入库数' else '5退不良' end ) as 类型 ,数量
from UFDATA_001_2015..BI_MES_RPT_DJQuery       
where isnull(数量,0)<>0 and 数量类型 like '[1,2,3]%') z
group by 日期,别名,类型

----select * from #tempabc where 别名='清溪产线9' and 日期='2022-05-25'
----3堆积数=1实际产能-2入库数

insert into #tempabc
select 日期,别名,'3堆积数' ,sum((case when 类型='1实际产能' then 白班 else 0 end )-(case when 类型='2入库数' then 白班 else 0 end ))  as 白班
,sum((case when 类型='1实际产能' then 夜班 else 0 end)-(case when 类型='2入库数' then 夜班 else 0 end)) as夜班
from #tempabc
group by 日期,别名
-----4堆积比例 =3堆积数/1实际产能 如果产能为0则比例为0
insert into #tempabc
select 日期,别名,'4堆积比例' , round((case when sum(case when 类型='1实际产能' then 白班 else 0 end )=0 then 0 else   sum(case when 类型='3堆积数' then 白班 else 0 end )/sum(case when 类型='1实际产能' then 白班 else 0 end ) end),4)
,round(( case when sum(case when 类型='1实际产能' then 夜班 else 0 end)=0   then 0 else  sum(case when 类型='3堆积数' then 夜班 else 0 end)/sum(case when 类型='1实际产能' then 夜班 else 0 end) end ),4)
from #tempabc
--- where 别名='清溪产线1' and 日期='2022-05-03'
group by 日期,别名
-----6 实际堆积=1实际产能-2良品入库-5退不良
insert into #tempabc
select 日期,别名,'6实际堆积' ,sum((case when 类型='1实际产能' then 白班 else 0 end )-(case when 类型='2入库数' then 白班 else 0 end )-(case when 类型='5退不良' then 白班 else 0 end ))  as 白班
,sum((case when 类型='1实际产能' then 夜班 else 0 end)-(case when 类型='2入库数' then 夜班 else 0 end)-(case when 类型='5退不良' then 夜班 else 0 end)) as 夜班
from #tempabc
group by 日期,别名
-----7退不良比例
insert into #tempabc
select 日期,别名,'7退不良比例' , round((case when sum(case when 类型='1实际产能' then 白班 else 0 end )=0 then 0 else   sum(case when 类型='5退不良' then 白班 else 0 end )/sum(case when 类型='1实际产能' then 白班 else 0 end ) end),4)
,round(( case when sum(case when 类型='1实际产能' then 夜班 else 0 end)=0   then 0 else  sum(case when 类型='5退不良' then 夜班 else 0 end)/sum(case when 类型='1实际产能' then 夜班 else 0 end) end ),4)
from #tempabc
group by 日期,别名
----8良品入库率= 2良品入库/1实际产能
insert into #tempabc
select 日期,别名,'8良品入库率' , round((case when sum(case when 类型='1实际产能' then 白班 else 0 end )=0 then 0 else   sum(case when 类型='2入库数' then 白班 else 0 end )/sum(case when 类型='1实际产能' then 白班 else 0 end ) end),4)
,round(( case when sum(case when 类型='1实际产能' then 夜班 else 0 end)=0   then 0 else  sum(case when 类型='2入库数' then 夜班 else 0 end)/sum(case when 类型='1实际产能' then 夜班 else 0 end) end ),4)
from #tempabc
group by 日期,别名
----9实际堆积比例=6实际堆积/1实际产能
insert into #tempabc
select 日期,别名,'9实际堆积比例' , round((case when sum(case when 类型='1实际产能' then 白班 else 0 end )=0 then 0 else   sum(case when 类型='6实际堆积' then 白班 else 0 end )/sum(case when 类型='1实际产能' then 白班 else 0 end ) end),4)
,round(( case when sum(case when 类型='1实际产能' then 夜班 else 0 end)=0   then 0 else  sum(case when 类型='6实际堆积' then 夜班 else 0 end)/sum(case when 类型='1实际产能' then 夜班 else 0 end) end ),4)
from #tempabc
group by 日期,别名


select *
from #tempabc
order by 日期,别名,类型
GO

回复

使用道具 举报

yhdata_yzm 显示全部楼层 发表于 2022-6-9 13:58:30
squall0828 发表于 2022-6-9 13:34
ALTER proc [dbo].[qy_ttt]
as

稍后我帮您看看
回复

使用道具 举报

阿姆斯特朗炮皇冠三 显示全部楼层 发表于 2022-6-9 16:34:20
SET NOCOUNT ON EXEC cc_cggl_cgsjtb ?{账期}
加上exec前面这那几个字母试试,我也是同样的问题,加上之后就行了
回复

使用道具 举报

yhdata_yzm 显示全部楼层 发表于 2022-6-9 16:44:58
可以参考下楼上的解决方案
回复

使用道具 举报

yhdata_yzm 显示全部楼层 发表于 2022-6-9 16:45:00
可以参考下楼上的解决方案
回复

使用道具 举报

yuan30铂金二 显示全部楼层 发表于 2024-1-23 11:40:59
yhdata_yzm 发表于 2022-6-9 16:44
可以参考下楼上的解决方案

相同的情况,pg数据库有什么方法可以解决
回复

使用道具 举报

高级模式
您需要登录后才可以回帖 登录 | 免费注册

  • 官方微信

    欢迎关注永洪服务号!收费为0,价值无限

    扫码关注
  • 新浪微博

    让每位用户轻松挖掘数据价值!

    访问新浪微博
  • 智能客服
50W

会员等你来哦

Copyright   ©2012-2024  北京永洪商智科技有限公司  (京ICP备12050607) 京公网安备110110802011451号 |联系社区管理员|《永洪社区协议》
返回顶部