从字符串转换为 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)+