Creating view using Openquery and embedded quotes

  • When creating a view, you state your selection criteria which can include character constants that are single quoted, such as 'ALL'.

    In the openquery function, the link server is the first parameter and the query statement is the second parameter. The statement must be a character string which means single quotes.

    How do you embed a quoted character constant in a qouted string, like the following:

    'Select * from customer where state = 'AL''

    Thanks.

  • Try This

    SET QUOTED_IDENTIFIER OFF

    GO

    SET ANSI_NULLS ON

    GO

    CREATE VIEW dbo.vw_test

    AS

    SELECT * FROM OPENQUERY(TEST,"Select * from customer where state = 'AL'")

    GO

    SET QUOTED_IDENTIFIER OFF

    GO

    SET ANSI_NULLS ON

    GO

  • You need to embed the quoted constants within another pair of single quotes:

    CREATE VIEW dbo.vw_test

    AS

    SELECT * FROM OPENQUERY(TEST,'Select * from customer where state = ''AL'' ')

    GO

    Tony Bater


    Tony

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply