declare @sql varchar(8000)
select @sql='select p.BillNumberID,p.BillCode,p.BtypeID,CompanyFullName=(select FullName from Btype where typeID=p.BtypeID ),p.ARTotal,p.LimitDate
from [otherAR] p 
where BillDate<='''+CONVERT(varchar(10),@chvEnddate,120)+'''
union all
select p.BillNumberID,p.InvoiceCode,p.BtypeID,p.CompanyFullName=(select FullName from Btype where typeID=p.BtypeID ),p.TotalTotal,p.LimitDate
from [InvoiceIndex] p
where BillDate<='''+CONVERT(varchar(10), @chvEnddate,120)+''''exec(@sql)

解决方案 »

  1.   

    TO: pengdali(大力 V3.0)
    不行,我试了报错啊:服务器: 消息 170,级别 15,状态 1,行 5
    第 5 行: '=' 附近有语法错误。
    服务器: 消息 170,级别 15,状态 1,行 5
    第 5 行: ',' 附近有语法错误。
      

  2.   

    declare @sql nvarchar(500),@chvEndDate nvarchar(20)
    set @chvEndDate='2001-02-03'
    select @sql='select p.BillNumberID,p.BillCode,p.BtypeID,CompanyFullName=
                 (select FullName from Btype where typeID=p.BtypeID ),p.ARTotal,p.LimitDate
    from [otherAR] p where BillDate<='''+@chvEnddate+''''
    exec(@sql)
      

  3.   


    select @sql='select p.BillNumberID,p.BillCode,p.BtypeID,CompanyFullName=(select FullName from Btype where typeID=p.BtypeID ),p.ARTotal,p.LimitDate
    from [otherAR] p
    where BillDate<='''+@chvEnddate+'''
    union all
    select p.BillNumberID,p.InvoiceCode,p.BtypeID,p.CompanyFullName=(select FullName from Btype where typeID=p.BtypeID ),p.TotalTotal,p.LimitDate
    from [InvoiceIndex] p
    where BillDate<='''+@chvEnddate+''''
      

  4.   

    select @sql='select p.BillNumberID,p.BillCode,p.BtypeID,(select FullName from Btype where typeID=p.BtypeID ),p.ARTotal,p.LimitDate
    from [otherAR] p where BillDate<='''+CONVERT(varchar(10),@chvEnddate,120)+''' union all select p.BillNumberID,p.InvoiceCode,p.BtypeID,(select FullName from Btype where typeID=p.BtypeID ),p.TotalTotal,p.LimitDate
    from [InvoiceIndex] p where BillDate<='''+CONVERT(varchar(10), @chvEnddate,120)+''''