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

请帮我看看这个存储过程有什么错误?
CREATE   PROCEDURE     spClientGetCNWinImportantProject
@PrevDateTime   datetime,  
@NextDateTime   datetime,
@FromDbName   nvarchar(50),
@ToDbName   nvarchar(50),
@Type   varchar(20)
AS
declare   @Str   varchar(5000)
declare   @recordcount   int
BEGIN   TRANSACTION   tranInStoreMaterialInfoRep
SET   @Str   =   N 'select   @recordcount   =   count(ProjectID)   from   [ '+@ToDbName+ '].[dbo].[CNWinImportantProject]   where   ProjectStartDate=[ '+@PrevDateTime+ ']   and   ProjectEndDate   =[ '+@NextDateTime+ ']   and   Type= '+@Type+ ' '
exec   sp_executesql   @Str,   N '@recordcount   int   output ',   @recordcount   output
if   (@recordcount   =0)
begin
EXEC( 'INSERT   INTO   [ '+@ToDbName+ '].[dbo].[CNWinImportantProject](
ProjectID,  
ProjectStartDate,  
ProjectEndDate,  
ConferTotalCost,  
CNWinTotalCost,  
Type,
IsUpload,
BelongMonth
)
select   projectid, '+@PrevDateTime+ ', '+@NextDateTime+ ',0,0, '+@Type+ ',0,0
from   [ '+@ToDbName+ '].[dbo].[SystemInitialize] ')
end
--如果更新失败则回滚事务
IF   @@error <> 0  
BEGIN
ROLLBACK   TRANSACTION   tranInStoreMaterialInfoRep
RETURN   -1
  END
COMMIT   TRANSACTION   tranInStoreMaterialInfoRep

RETURN   1
GO

错误1:服务器:   消息   241,级别   16,状态   1,过程   spClientGetCNWinImportantProject,行   12
从字符串转换为   datetime   时发生语法错误。

错误2:服务器:   消息   170,级别   15,状态   1,行   11
第   11   行:   '1 '   附近有语法错误。


------解决方案--------------------
ProjectStartDate=[ ' ' '+@PrevDateTime+ ' ' '] and ProjectEndDate =[ ' ' '+@NextDateTime+ ' ' '] and Type= '+@Type+ ' '