- SQL code
declare @a smalldatetime,@b int,@bdate smalldatetimeset @a='1905-3-31'set @b=2select @bdate=(dateadd(mm,@b,@a))exec('select * from ABC where BDate='+@bdate+'')
请各位大神帮忙看看,执行结果总是显示
'31' 附近有语法错误
如果改成BDate="'+@bdate+'"'的话会显示
列名 '05 31 1905 12:00AM' 无效
不知道这条语句到底该怎么写才对
------解决方案--------------------
declare @a smalldatetime,@b int,@bdate smalldatetime
set @a='1905-3-31'
set @b=2
select @bdate=(dateadd(mm,@b,@a))
exec('select * from ABC where BDate='''+@bdate+'''')