Java调用SqlServer中的存储过程出现结果集为空的情况

Navicat上测试存储过程正常,程序里面调取数据为空
原存储过程:
单独测试,供应商名称和供应商编号都可以获得数据

ALTER procedure PRO_Real_time_inventory
@dwbh_zh varchar(100),   -----供应商编号
@dwmch varchar(100)     ------供应商名称
as
begin
select DATENAME(year,a.rq)+'-'+DATENAME(month,a.rq) as rq,sum(a.jcje) as jcje 
from view_Real_time_inventory  a 
where a.rq>=dateadd(month, datediff(month, 0, dateadd(month,-12,getdate())), 0) and a.rq<dateadd(month, datediff(month, 0,getdate()), 0) and a.dwmch  like '%'+@dwmch+'%' and a.dwbh_zh  like '%'+@dwbh_zh+'%' 
group by DATENAME(year,a.rq)+'-'+DATENAME(month,a.rq)
end

 

存储过程存在问题
1.Java调用参数的时候只传了供应商编号,没有传供应商名称,传空串就有数据集
2.Navicat测试正常是应为不填默认空串

修改方案1:
单独查询

ALTER procedure PRO_Real_time_inventory
@dwbh_zh varchar(100),   -----供应商编号
as
begin
select DATENAME(year,a.rq)+'-'+DATENAME(month,a.rq) as rq,sum(a.jcje) as jcje 
from view_Real_time_inventory  a 
where a.rq>=dateadd(month, datediff(month, 0, dateadd(month,-12,getdate())), 0) and a.rq<dateadd(month, datediff(month, 0,getdate()), 0) and a.dwbh_zh  = ''+@dwbh_zh+'' 
group by DATENAME(year,a.rq)+'-'+DATENAME(month,a.rq)
end

修改方案2:
程序里面查询的时候默认另一个参数为空串

posted @ 2022-01-21 15:21  贾斯丁哔哔  阅读(320)  评论(0)    收藏  举报