0

Is there any way to declare a variable inside an OPENQUERY statement (querying MySQL db). I only want to declare a variable inside the actual statement. So I don't need to pass a variable into the statement (I know this isn't possible).

Is it possible to declare a variable inside the openquery statement?

SELECT *
FROM OPENQUERY([SERVER], '
            SET @s = 1;
            SELECT 
                @s
            '  
           )

This returns the error

Cannot process the object. The OLE DB provider **** for linked server ***** indicates that either the object has no columns or the current user does not have permissions on that object.

redstubble
  • 121
  • 2
  • 12
  • Can;t you do `OPENQUERY([SERVER], 'SELECT ' + '1'?` – artm May 19 '17 at 01:20
  • Yes I can but I am using @s multiple times throughout the query. So would like to declare it once and use it multiple times. – redstubble May 19 '17 at 01:27
  • Hmm ok. One workaround I can think of is building the query with @ xyz and then use replace to replace all @ xyz with 1, though I know that's not what you are asking. – artm May 19 '17 at 01:38

0 Answers0