问题答案: |
解决方法:
方法一:将操作员名称控制在6个字符以内。
方法二:在查询分析器中执行如下脚本
SET QUOTED_IDENTIFIER ON GO SET ANSI_NULLS ON GO
ALTER PROCEDURE [sprecordcash] (@begindate datetime ='2008-11-29',@enddate datetime='2008-11-29', @pk_record_cash varchar(16)='',@bizcode varchar(32)='01',@corp varchar(32)='1001') as declare @kssj datetime, @jssj datetime, @paySql varchar(1000), @restype varchar(1000), @Sql varchar(8000), @begin varchar(20), @end varchar(20) create table #Datas( pk varchar(40) null, pk_record_cash varchar(40) null, begintime varchar(20) null, endtime varchar(20) null, consname varchar(120) null, conscode varchar(60) null, 金额 float null, 笔数 int null, discount float null, premoney float null, dismant float null, accmoney float null, serfeemoney float null, othmoney float null, invaddmoney float null, resmoney float null, invmoney float null
)
if (@corp is null) or (@corp='') set @corp='%' else set @corp=@corp+'%' if (@bizcode is null) or (@bizcode='') set @bizcode='%' else set @bizcode=@bizcode+'%' if @bizcode='%' begin set @kssj=' 9:00:01' set @jssj=' 9:00:00' end else begin set @kssj=(select top 1 min(Convert(char(10),fromtime,108)) from bd_biztype where bizcode like @bizcode and pk_corp like @corp) set @jssj=(select top 1 max(Convert(char(10),totime,108)) from bd_biztype where bizcode like @bizcode and pk_corp like @corp and fromtime>totime) if @jssj is null set @jssj=(select top 1 max(Convert(char(10),totime,108)) from bd_biztype where bizcode like @bizcode and pk_corp like @corp and fromtime<totime) end if @kssj<@jssj begin set @begin=Convert(char(10),@begindate,112)+@kssj set @end=Convert(char(10),@enddate,112)+@jssj end else begin set @begin=Convert(char(10),@begindate,112)+@kssj set @end=Convert(char(10),@enddate+1,112)+@jssj end if (@begin is null) or (@begin='') set @begin=Convert(char(10),@begindate,112)+' 00:00:00' if (@end is null) or (@end='') set @end=Convert(char(10),@enddate,112)+' 23:59:59' if (@pk_record_cash is null) or (@pk_record_cash='') set @pk_record_cash='%'
insert #Datas(pk,pk_record_cash,consname,conscode,金额,笔数) select a.pk_record_cash,isnull(b.name,'未知'),isnull(d.paymentname,'未知'),isnull(c.paymentcode,'zz'),sum(isnull(c.money,0)),count(a.pk_cash) from so_shopping a left join SYSTEM_EIP..pub_operator b on b.operatorid=a.pk_record_cash left join so_shopping_b c on c.pk_cash=a.pk_cash left join bd_payment d on d.paymentcode=c.paymentcode and d.pk_corp=a.pk_corp where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and a.pk_record_cash like @pk_record_cash group by a.pk_record_cash,isnull(b.name,'未知'),d.paymentname,c.paymentcode
insert #Datas(pk,pk_record_cash,consname,conscode,金额,笔数) select pk,isnull(pk_record_cash,'未知'),'合计','zzzzzz',sum(isnull(金额,0)),sum(isnull(笔数,0)) from #Datas group by pk,isnull(pk_record_cash,'未知')
update #Datas set discount=( select sum(isnull(discount,0)) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk ) update #Datas set premoney=( select sum(isnull(premoney,0)) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk ) update #Datas set dismant=( select sum(isnull(dismant,0)) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk ) update #Datas set accmoney=( select sum(isnull(accmoney,0)) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk ) update #Datas set serfeemoney=( select sum(isnull(serfeemoney,0)) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk ) update #Datas set othmoney=( select sum(isnull(othmoney,0)) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk ) update #Datas set invaddmoney=( select sum(isnull(invaddmoney,0)) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk ) update #Datas set resmoney=( select sum(isnull(resmoney,0)) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk )
update #Datas set invmoney=( select sum(isnull(invmoney,0)) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk )
if convert(char(10),@begindate,112)=convert(char(10),@enddate,112) begin update #Datas set begintime=(select top 1 convert(char(8),cashtime,108) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk order by cashtime) update #Datas set endtime=(select top 1 convert(char(8),cashtime,108) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk order by cashtime desc) end else begin update #Datas set begintime=(select top 1 convert(char(10),cashtime,111) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk order by cashtime) update #Datas set endtime=(select top 1 convert(char(10),cashtime,111) from so_shopping a where isnull(a.bizcode,'') like @bizcode and a.cashtime between @begin and @end and isnull(a.pk_corp,'') like @corp and pk_record_cash=#Datas.pk order by cashtime desc) end if @@rowcount>0 begin print'0' exec AnalyData '#Datas','pk,pk_record_cash,begintime,endtime, discount,premoney,dismant,accmoney,serfeemoney,othmoney,invaddmoney,resmoney,invmoney', 'consname','金额,笔数','conscode','pk_record_cash',1,'desc','sum' end else begin select * from #Datas print '1' end drop table #Datas
GO SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS ON GO
|