Try executing `SET QUOTED_IDENTIFIERS ON` before running this query. Recent 
versions of Sequel included the `ansi` connection option, which causes 
Sequel to behave more like most other clients -- this is one of the 
settings it affects.

If this doesn't do the trick, SQL Server uses `[]` for identifier quoting, 
so perhaps this will work:

@db["SELECT * FROM OPENQUERY([SQL02.DEV <http://sql02.dev/>] , 'SELECT 
@@version')"].all



On Wednesday, July 8, 2020 at 8:35:10 PM UTC-5, KING SABRI wrote:
>
> Thank you for your response
> In the official documentation, they are using a variable not an actual 
> hostname. I tried to use the hostname *without* quotes on another SQL 
> client and it returns "incorrect synatx"
>
> I also tried the same query on other GUI SQL client (such as Sqlectron 
> and heidisql) and it works well. 
> It seems that using anything but double-quotes with the hostname raise an 
> error. Also only single quotes are accepted for the query. (tested on GUI 
> client)
>
>
> On Thursday, July 9, 2020 at 1:47:47 AM UTC+3, Jeremy Evans wrote:
>>
>> On Wednesday, July 8, 2020 at 3:38:00 PM UTC-7, KING SABRI wrote:
>>>
>>> Hi all 
>>>
>>> I'm trying to use OPENQUERY using sequel and I'm always getting syntax 
>>> error 
>>>  
>>>
>>>> @db["SELECT * FROM OPENQUERY(\"SQL02.DEV\" , 'SELECT @@version')"].all
>>>
>>>
>>> *The error is *
>>>
>>> Sequel::DatabaseError: TinyTds::Error: Incorrect syntax near 'SQL02.DEV
>>> '.
>>> from 
>>> /var/lib/gems/2.7.0/gems/sequel-5.34.0/lib/sequel/adapters/tinytds.rb:217:in
>>>  
>>> `fields'
>>> Caused by TinyTds::Error: Incorrect syntax near 'SQL02.DEV'.
>>> from 
>>> /var/lib/gems/2.7.0/gems/sequel-5.34.0/lib/sequel/adapters/tinytds.rb:217:in
>>>  
>>> `fields'
>>> Caused by Sequel::DatabaseError: TinyTds::Error: Unclosed quotation mark 
>>> after the character string '''.
>>> from 
>>> /var/lib/gems/2.7.0/gems/sequel-5.34.0/lib/sequel/adapters/tinytds.rb:217:in
>>>  
>>> `fields'
>>> Caused by TinyTds::Error: Unclosed quotation mark after the character 
>>> string '''.
>>> from 
>>> /var/lib/gems/2.7.0/gems/sequel-5.34.0/lib/sequel/adapters/tinytds.rb:217:in
>>>  
>>> `fields'
>>>
>>> I've tried various ways to by changing double-quotes to single-quotes, 
>>> quotes escaping but no luck. 
>>>
>>> PS: Queries such as SELECT @@version work well. The issue I'm facing is 
>>> only with OPENQUERY.
>>>
>>> -> Sequel::VERSION 
>>> => 5.34.0
>>>
>>
>> From looking at the OPENQUERY documentation, the first argument does not 
>> appear to need quoting: 
>> https://docs.microsoft.com/en-us/sql/t-sql/functions/openquery-transact-sql?view=sql-server-ver15
>>
>> In any case, this doesn't appear to be a problem with Sequel, as Sequel 
>> is raising an error because your SQL is invalid. If you continue to need 
>> help on producing valid SQL for OPENQUERY, you should probably ask on an 
>> MSSQL-specific forum.
>>
>> Thanks,
>> Jeremy 
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/731887a3-1092-4ccf-957c-4a7f7e97bf41o%40googlegroups.com.

Reply via email to