如何在动态SQL中引用DateTime变量
以下语句报错:Msg241 Conversion failed when converting datetime from character sting
-----------------------
DECLARE @Day DATETIME
SET @Day= '4/6/2003 '
DECLARE @sql varchar (300)
SET @sql= 'SELECT '+ '@Day
EXEC (@sql)
why
------解决方案--------------------@day是日期,不是字符串,应该转成字符串,比如:set @sql= 'select '+convert(varchar,@day,112)