我有这个SQL查询:
DECLARE @VAR varchar(8)
SET @VAR = '20140202'
SELECT * FROM OPENQUERY([NMD],'SELECT * FROM NmdItemGroups01.dbo.InvTranDtl WHERE TranDate = ''' + @VAR + '''')
但是当我运行它时,会出现此错误:
Incorrect syntax near '+'
答案 0 :(得分:2)
sp_executesql示例:
DECLARE @VAR varchar(8)
SET @VAR = '20140202'
EXEC sp_executesql
N'SELECT * FROM NmdItemGroups01.dbo.InvTranDtl WHERE TranDate = @TranDate',
N'@TranDate DATE',
@VAR