April 27, 2010 at 6:41 am
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
April 27, 2010 at 12:40 pm
Just remove the barckets and quotation marks from your variable reference:
SELECT * FROM #Test WHERE col2.exist('/root/tag1[@level=sql:variable("@var")]') = 1
April 27, 2010 at 2:27 pm
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