Voglio ottenere il valore dell'attributo da XML utilizzando Xquery.Come ottenere un valore dall'attributo XML utilizzando Sql: Variabile in xquery
MY XML è
<Answers>
<AnswerSet>
<Answer questionId="NodeID">155</Answer>
<Answer questionId="ParentNode" selectedValue="12">Product</Answer>
</AnswerSet>
</Answers>
Qui di seguito è la mia interrogazione.
DECLARE @Field Varchar(100)
DECLARE @Attribute VARCHAR(100)
SET @Field='ParentNode'
SET @Attribute = 'selectedValue'
SELECT ISNULL(PropertyXML.value('(/Answers/AnswerSet/Answer[@questionId=sql:variable("@Field")])[1]','varchar(max)'),'') ,
isnull (PropertyXML.value ('(/ Risposte/AnswerSet/Risposta [@ QuestionID = sql: variable ("@ Campo")]/sql: variable (@attribute)) [1]',' varchar (max) '),' ') dal nodo WHERE id = 155
sotto la linea sta lavorando bene con sql: variable
ISNULL(PropertyXML.value('(/Answers/AnswerSet/Answer[@questionId=sql:variable("@Field")])[1]','varchar(max)'),'')
ma sto ottenendo errore nella linea seguente ..
ISNULL(PropertyXML.value('(/Answers/AnswerSet/Answer[@questionId=sql:variable("@Field")]/sql:variable(@Attribute))[1]','varchar(max)'),'')
Voglio ottenere valore attributo (@Attribute) nel risultato.
Quale versione di SQL Server? Se stai usando .valore, deve essere 2005+ –
sì 2005 e 2008 – Mohmedsadiq