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

从字符串转换为 datetime 时发生语法错误
set   @Sql= '   INSERT   INTO   [zqgx].[dbo].[myAdInfo]     (   [cAdInfoTitle],   [iAdInfoClassId],   [cAdInfoPic],   [cAdInfoContent],   [dAdInfoAvailabilityTime],   [cAdInfoContact],   [cAdInfoPhone],   [cAdInfoType],   [iUserId])     VALUES  
(     ' ' '+@cAdInfoTitle+ ' ' ',   '+convert(varchar(10),@iAdInfoClassId)+ ',   ' ' '+@cAdInfoPic+ ' ' ',   ' ' '+@cAdInfoContent+ ' ' ', ' ' '+convert(datetime,@dAdInfoAvailabilityTime,120)+ ' ' ', ' ' '+@cAdInfoContact+ ' ' ',   ' ' '+@cAdInfoPhone+ ' ' ',   ' ' '+@cType+ ' ' ',   '+convert(varchar(10),@iUserId)+ ') '

exec   (@Sql)
-------------注意这里不行-------
' ' '+convert(datetime,@dAdInfoAvailabilityTime,120)+ ' ' '
------------但改成--------------
' '2007-8-30 ' '
却可以了..为什么呢?



------解决方案--------------------
convert(datetime,@dAdInfoAvailabilityTime,120)+
改成
convert(datetime,@dAdInfoAvailabilityTime,103)+