日期:2014-05-18  浏览次数:20471 次

谁能给我检查一下,下面这个动态SQL有什么问题(在线等待......)
declare   @sql1   varchar(8000)
declare     @FBrnoName     varchar(100)
declare   @FdateFrom   datetime
declare   @FdateEnd     datetime
declare   @FAccountNumberFrom   nvarchar(100)
declare   @FAccountNumberEnd   nvarchar(100)
set   @FBrnoName= '实业有限公司 '
set   @FdateFrom= '2007-01-01 '
set   @FdateEnd= '2007-01-31 '
set   @FAccountNumberFrom= '5101.001.001 '
set   @FAccountNumberEnd= '5101.005.002 '

set   @sql1   =   'Update   '+@FBrnoName+ '..t_Voucher   set   FImportID=0   WHERE     FVoucherID   IN(select   DISTINCT   v.FVoucherID  
from   '+@FBrnoName+ '..t_Voucher   v   INNER   JOIN       '+@FBrnoName+ '..t_VoucherEntry     a     ON   v.FVoucherID=a.FVoucherID
  left   outer   join   '+@FBrnoName+ '..   t_Account   b   on   a.FAccountID=b.FAccountID     where   v.Fdate   > =   ' ' '+convert(char(10),@FdateFrom,121)+ ' ' '
And   v.Fdate   <= '+convert(char(10),@FdateEnd,121)+ 'and   b.Fnumber   > =   ' ' '+@FAccountNumberFrom+ ' ' '
And   b.Fnumber   <= ' ' '+@FAccountNumberEnd+ ' ' ') '
EXEC(@sql1)

------解决方案--------------------
print(@sql1) 出来后没有语法错啊.


------解决方案--------------------
declare @sql1 nvarchar(4000)
declare @FBrnoName nvarchar(100)
declare @FdateFrom datetime
declare @FdateEnd datetime
declare @FAccountNumberFrom nvarchar(100)
declare @FAccountNumberEnd nvarchar(100)
set @FBrnoName=N '实业有限公司 '
set @FdateFrom= '2007-01-01 '
set @FdateEnd= '2007-01-31 '
set @FAccountNumberFrom= '5101.001.001 '
set @FAccountNumberEnd= '5101.005.002 '

set @sql1 = 'Update '+@FBrnoName+ '..t_Voucher set FImportID=0 WHERE FVoucherID IN(select DISTINCT v.FVoucherID
from '+@FBrnoName+ '..t_Voucher v INNER JOIN '+@FBrnoName+ '..t_VoucherEntry a ON v.FVoucherID=a.FVoucherID
left outer join '+@FBrnoName+ '.. t_Account b on a.FAccountID=b.FAccountID where v.Fdate > = ' ' '+convert(char(10),@FdateFrom,121)+ ' ' '
And v.Fdate <= ' ' '+convert(char(10),@FdateEnd,121)+ ' ' ' and b.Fnumber > = ' ' '+@FAccountNumberFrom+ ' ' '
And b.Fnumber <= ' ' '+@FAccountNumberEnd+ ' ' ') '
print @sql1
EXEC(@sql1)

------解决方案--------------------
convert(char(10),@FdateEnd,121) 两边少了引号
------解决方案--------------------
declare @sql1 varchar(8000)
declare @FBrnoName varchar(100)
declare @FdateFrom datetime
declare @FdateEnd datetime
declare @FAccountNumberFrom nvarchar(100)
declare @FAccountNumberEnd nvarchar(100)
set @FBrnoName= '实业有限公司 '
set @FdateFrom= '2007-01-01 '
set @FdateEnd= '2007-01-31 '
set @FAccountNumberFrom= '5101.001.001 '
set @FAccountNumberEnd= '5101.005.002 '

set @sql1 = 'Update v set FImportID=0 WHERE FVoucherID IN(select DISTINCT v.FVoucherID
from '+@FBrnoName+ '..t_Voucher v INNER JOIN '+@FBrnoName+ '..t_Vouc