Skip to main content
InSource Solutions

TN Hist222 Using Variables With OpenQuery

insource logo large.jpg



This article is a quick outline of a work around to using variables with OpenQuery - as you cannot directly use variables with OpenQuery.


  • Author: Lewis Talley
  • Published: 07/28/2015
  • Applies to: InSQL (10.0 +)




OpenQuery does not support passing variables as shown below in the query that does not work:

Original Query.png


The work around is to build your SQL query as a string - including the variables you want to include and then calling the ExecuteSQL stored procedure as shown below:

String Query.png