0

This is a unique problem..I think. So my goal is to input a variable and get a row from my column. Let me explain a little with the code im doing.

 SELECT
  pref.query('Database/text()') as PersonSkills,
  pref.query('FillQuery/text()') as PersonSkills,
  pref.query('TabText/text()') as PersonSkills,
  pref.query('TooltipText/text()') as PersonSkills
  FROM  table CROSS APPLY
  Tag.nodes('/Root/Configuration/TaskSelectorControl/QueueSelector') AS People(pref)

this works fine. However what I need to do is pass in the last part, the queue selector as a variables.

 DECLARE @Xml XML
 DECLARE @AttributeName VARCHAR(MAX) = 'QueueSelector'
 SELECT
 pref.query('Database/text()') as PersonSkills,
  pref.query('FillQuery/text()') as PersonSkills,
  pref.query('TabText/text()') as PersonSkills,
  pref.query('TooltipText/text()') as PersonSkills
  FROM  table CROSS APPLY
Tag.nodes('/Root/Configuration/TaskSelectorControl[@Name=sql:variable("@AttributeName")]
 ') AS People(pref)

this doesnt work, any ideas why?

Well, I kinda lied. the bottom works, however it returns an empty dataset

1 Answer 1

1
/Root/Configuration/TaskSelectorControl/QueueSelector

is not equivalent to:

/Root/Configuration/TaskSelectorControl[@Name='QueueSelector']

The above XPath selects <TaskSelectorControl Name="QueueSelector">, not <QueueSelector> children of <TaskSelectorControl>.

You could either do this in XPath:

/Root/Configuration/TaskSelectorControl/*[local-name(.)=sql:variable("@AttributeName")]

Or it might be simpler to concat prior to evaluating:

'/Root/Configuration/TaskSelectorControl/' + @AttributeName
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.