none
OPENQUERY with quotes in the query string

    Question

  • Hello,

     

    how can I use the following statement with OPENQERY syntax:

     

    SELECT 'hello world' FROM mytable

     

    Maybe I have to transform quite a few and complex SQL-statements to the OPENQUERY syntax. Obviously I have problems with single quotes

     

    SELECT * FROM OPENQUERY(LINKEDSERVER, 'select 'hello world' from mytable')

     

    quotename('hello world', '''') does not help  because this will create 'hello world' instead of hello world (w/o quotes).

    How can I transform my SQL-statements with quotes to Openquery syntax?

     

    regards

     

    arno

    Thursday, January 17, 2008 12:33 PM

Answers

  • Try:

     

    Code Block

    SELECT * FROM OPENQUERY(LINKEDSERVER, 'select ''hello world'' from mytable')

     

     

    Also, welcome to the SQL Forums, Arno.

    Thursday, January 17, 2008 12:58 PM
    Moderator
  • Code Block
    SELECT * FROM OPENQUERY(LINKEDSERVER, 'select ''hello world'' from mytable')

     

    *LOL*

    yes, this works.

     

    I have seen so many three- and four quotation marks when concatenating texts, variables, dealing with spaces etc. in so many programming languages so that it is very suprising that "just put quotation marks around" simply works.

     

    Kent, thank's a lot!

     

    arno

    Thursday, January 17, 2008 1:20 PM

All replies

  • Try:

     

    Code Block

    SELECT * FROM OPENQUERY(LINKEDSERVER, 'select ''hello world'' from mytable')

     

     

    Also, welcome to the SQL Forums, Arno.

    Thursday, January 17, 2008 12:58 PM
    Moderator
  • Code Block
    SELECT * FROM OPENQUERY(LINKEDSERVER, 'select ''hello world'' from mytable')

     

    *LOL*

    yes, this works.

     

    I have seen so many three- and four quotation marks when concatenating texts, variables, dealing with spaces etc. in so many programming languages so that it is very suprising that "just put quotation marks around" simply works.

     

    Kent, thank's a lot!

     

    arno

    Thursday, January 17, 2008 1:20 PM