sql server 2008中的存储过程执行与单独执行SQL语句结果不一致
涵妈妈 2018-10-16 09:37:46 存储过程:
ALTER PROCEDURE [dbo].[cb_4s_ds]
@startdate1 datetime,@enddate1 datetime
AS
BEGIN
SET NOCOUNT ON;
select a.resourcecode,a.resourcename,count(distinct a.frameno) liangshu,sum(a.sumpremium) bnbaofei into #bncbhuizong
from NewData a
where a.operatedate between @startdate1 and @enddate1
group by a.resourcecode,a.resourcename
select b.resourcecode,count(distinct b.frameno) dsliangshu,sum(b.sumverilossfee) bndsjiner into #bndshuizong
from dsdata b
where b.enddeflossdate between @startdate1 and @enddate1
group by b.resourcecode
select a.resourcecode,a.resourcename,liangshu,cast(bnbaofei/10000 as decimal(38,2)) baofei1,b.dsliangshu,cast(bndsjiner/10000 as decimal(38,2))dsjiner,
cast(cast(b.bndsjiner*100/a.bnbaofei as decimal(38,2)) as varchar)+'%' AS rate
from #bncbhuizong a left join #bndshuizong b
on a.resourcecode=b.resourcecode
order by cast(b.bndsjiner*100/a.bnbaofei as decimal(38,2)) desc
END
exec cb_4s_ds'2018-10-12','2018-10-14'
单独执行SQL:
select a.resourcecode,a.resourcename,count(distinct a.frameno) liangshu,sum(a.sumpremium) bnbaofei into #bncbhuizong
from NewData a
where a.operatedate between '2018-10-12' and '2018-10-12'
group by a.resourcecode,a.resourcename
select b.resourcecode,count(distinct b.frameno) dsliangshu,sum(b.sumverilossfee) bndsjiner into #bndshuizong
from dsdata b
where b.enddeflossdate between '2018-10-12 00:00:00' and '2018-10-14 00:00:00'
group by b.resourcecode
select a.resourcecode,a.resourcename,liangshu,cast(bnbaofei/10000 as decimal(38,2)) baofei1,b.dsliangshu,cast(bndsjiner/10000 as decimal(38,2))dsjiner,
cast(cast(b.bndsjiner*100/a.bnbaofei as decimal(38,2)) as varchar)+'%' AS rate
from #bncbhuizong a left join #bndshuizong b
on a.resourcecode=b.resourcecode
order by cast(b.bndsjiner*100/a.bnbaofei as decimal(38,2)) desc
以上存储过程执行和单独SQL执行中的部分结果是不一致的,请给予帮助解决,谢谢!