sql:variable() function and exist() method problem

  • What is wrong with this statement?

    IF OBJECT_ID('tempdb.dbo.#Test') IS NOT NULL

    DROP TABLE #Test

    CREATE TABLE #Test (id int identity primary key, col2 xml)

    INSERT INTO #Test (col2) VALUES ('<root><tag1 level="ala">eeee</tag1></root>')

    INSERT INTO #Test (col2) VALUES ('<root><tag1 level="ela">eeee</tag1></root>')

    INSERT INTO #Test (col2) VALUES ('<root><tag1 level="ola">eeee</tag1></root>')

    DECLARE @var nvarchar(100) = 'ala'

    SELECT * FROM #Test WHERE col2.exist('/root/tag1[@level="{sql:variable("@var")}"]') = 1

  • Just remove the barckets and quotation marks from your variable reference:

    SELECT * FROM #Test WHERE col2.exist('/root/tag1[@level=sql:variable("@var")]') = 1



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • Thanks for help!

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

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