注册 登录
编程论坛 SQL Server论坛

语句提示错误

yclm 发布于 2022-01-22 19:39, 1416 次点击
ALTER PROC [dbo].[proc_XSth]
  @GSCODE varchar(20)='A002',
 @where varchar(6000)='1=1'
as
 declare @sqlcmd varchar(8000)
if @where='1=1' set @where = 'year(ckdate)=year(getdate()) and month(ckdate)=month(getdate())'
  set @sqlcmd ='
  select * from (
select WRITEDATE,ckdate,GUESTNAME,paydate,CKPAPER,PCODE,PNAME,PSIZE,PFACTORY,CKAMOUNT,XSPRICE,销售总金额=CKAMOUNT*XSPRICE,TXSPRICE,实售总金额=CKAMOUNT*TXSPRICE,COSTPRICE,  TCOSTPRICE,   KCPOSI, KCDEPOT, KCAMOUNT,  OPERATOR, PAYTYPE
from [dbo].[v_pjck] where ckamount<0  AND GSCODE=''A002'' AND '+@where+'
union all
select '''','''','''','''','''','''','''','''',''合计:'',sum(CKAMOUNT),''0'' , sum(CKAMOUNT*XSPRICE),           ''0'', sum(CKAMOUNT*tXSPRICE),   sum(COSTPRICE),SUM(TCOSTPRICE),'''' ,''''  ,sum(KCAMOUNT), '''',    ''''
from [dbo].[v_pjck] where GSCODE=''A002'' AND '+@where+') t
'

 print (@sqlcmd)
 exec (@sqlcmd)
 


    select *  from (
 select ckdate,a.ckpaper,guestname,operator,incharge,paytype,paydate,fptype,a.fhmode,pcode,pname,psize,pfactory,ckamount,COSTPRICE,TCOSTPRICE,xsprice,sumxsprice=ckamount*xsprice*(100-yhl)/100,txsprice,sumtxsprice=ckamount*txsprice*(100-yhl)/100,CKAMOUNT*costprice,CKAMOUNT*tcostprice,xsml=ckamount*(xsprice*(100-yhl)/100*((100-fppoint)/100)-costprice),txsml=ckamount*(txsprice*(100-yhl)/100*((100-fppoint)/100)-costprice),kcdepot,kcposi,pjid,b.writedate
 from pj_ckls a left join pj_cklssub b on a.ckpaper=b.ckpaper where A.gscode='A001' AND guestname LIKE '%开思%' and year(ckdate)=year(getdate()) and month(ckdate)=month(getdate())
 union all
 select '','','','','','','','','','','','','合计:',sum(ckamount),sum(ckamount*COSTPRICE),sum(ckamount*TCOSTPRICE),'0',sum(ckamount*xsprice*(100-yhl)/100),'0',sum(ckamount*txsprice*(100-yhl)/100),'0','0',sum(ckamount*(xsprice*(100-yhl)/100*((100-fppoint)/100)-costprice)),sum(ckamount*(txsprice*(100-yhl)/100*((100-fppoint)/100)-costprice)),'','','',''
 from pj_ckls a left join pj_cklssub b on a.ckpaper=b.ckpaper where A.gscode='A001' AND guestname LIKE '%开思%'and year(ckdate)=year(getdate()) and month(ckdate)=month(getdate())) as t
   
消息 8155,级别 16,状态 2,第 7 行
没有为 't' 的列 21 指定任何列名称。
消息 8155,级别 16,状态 2,第 7 行
没有为 't' 的列 22 指定任何列名称。
0 回复
1