打开查询错误 'Incorrect Syntax near keyword Transaction'

Openquery error 'Incorrect Syntax near keyword Transaction'

我有一个存储过程,它使用 openquery 从链接服务器中的 table 获取数据。 我需要在查询中传递一个参数,所以它如下

   Declare @query nvarchar(max)
   Declare @empRequestid nvarchar(max)
   
   Set @empRequestid = '100001' --(This is an input parameter)
   
   Set @query = 'SELECT * INTO [dbo].tblEmp_Report FROM OPENQUERY (SALESIT_SC3VIS_DEV, 
   ''SELECT EmployeeName, EmployeeNumber
   FROM   XXEmployee_Temp_ReportTable        
   WHERE  1=1        AND  description =''Transaction Employee Report''      
   and emp_requestid ='+@empRequestid +'        
   ORDER  BY period_id'')'

   EXEC(@query)

得到的错误是,
关键字 'Transaction' 附近的语法不正确。

我做错了什么?

试试这个:

   Declare @query nvarchar(max)
   Declare @empRequestid nvarchar(max)
   
   Set @empRequestid = '100001' --(This is an input parameter)
   
   Set @query = 'SELECT * INTO [dbo].tblEmp_Report FROM OPENQUERY (SALESIT_SC3VIS_DEV, 
   ''SELECT EmployeeName, EmployeeNumber
   FROM   XXEmployee_Temp_ReportTable        
   WHERE  1=1        AND  description =''''Transaction Employee Report''''
   and emp_requestid ='+@empRequestid +'        
   ORDER  BY period_id'')'


   SELECT @query

使用打印查询查找问题

Declare @query nvarchar(max)
Declare @empRequestid nvarchar(max)

Set @empRequestid = '100001' --(This is an input parameter)

Set @query = 'SELECT * INTO [dbo].tblEmp_Report FROM OPENQUERY (SALESIT_SC3VIS_DEV, 
''SELECT EmployeeName, EmployeeNumber
FROM   XXEmployee_Temp_ReportTable        
WHERE  1=1        AND  description =''Transaction Employee Report''      
and emp_requestid ='+@empRequestid +'        
ORDER  BY period_id'')'

Print(@query)

现在运行查询并找到问题然后将“打印”更改为“执行”