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

帮我看看最后那条SQL语句哪错了?
declare   @PrevDateTime   datetime
declare   @NextDateTime   datetime
declare   @FromDbName   varchar(50)
declare   @ToDbName   varchar(50)
declare   @Type   varchar(20)
declare   @ITBProjectPrice   money
declare   @ContractPrice   money
declare   @PurchaseOrderPrice   money
declare   @ITBProjectPriceint     int
declare   @ContractPriceint   int
declare   @PurchaseOrderPriceint   int
declare   @recordcount   int
declare   @sql   varchar(8000)
declare   @str   nvarchar(1000)
set   @PrevDateTime   =   '2007-1-1   00:00:01 '
set   @NextDateTime   =   '2007-1-7   23:59:59 '
set   @FromDbName   =   'DataResource '
set   @ToDbName   =   'DataTransfer_Client '
set   @Type   =   'W '
set   @str   =   N 'select   @recordcount   =   count(ProjectID)   from   [ '+@ToDbName+ '].[dbo].[ProjectBaseData]   where   ProjectStartDate= ' ' '+convert(varchar,@PrevDateTime,120)+ ' ' '   and   ProjectEndDate   = ' ' '+convert(varchar,@NextDateTime,120)+ ' ' '   and   Type= ' ' '+@Type+ ' ' ' '  
exec   sp_executesql   @str,   N '@recordcount   int   output ',   @recordcount   output
if   (@recordcount   =0)
begin
--招标金额
set   @str   =   N 'select   @ITBProjectPriceint   =   COUNT(*)   from
(
select   [ '+@ToDbName+ '].dbo.fnGetCurrencyExchangeRate(t1.CurrencyID,t1.EstimateCost)   as   EstimateCost
from   [ '+@FromDbName+ '].[dbo].[ServiceRequest]   as   t1,
(
select   distinct   TenderNO   ,SRID   from   [ '+@FromDbName+ '].[dbo].[ITB]   where   IsCanceled   <>   1   and   SendOutDate   > =   ' ' '+convert(varchar,@PrevDateTime,120)+ ' ' '   and   SendOutDate   <   ' ' '+convert(varchar,@NextDateTime,120)+ ' ' '
)   as   t2   where   t1.SRID   =   t2.SRID
)   AS   A   where   A.EstimateCost   <   0 '

报错:服务器:   消息   170,级别   15,状态   1,行   30
第   30   行:   ' '
)   as   t2   where   t1.SRID   =   t2.SRID
)   AS   A   where   A.EstimateCost   <   0 '   附近有语法错误。

------解决方案--------------------
少end