I am trying to pass the xpath as parameter to the query.
declare @test as nvarchar(1000) = '(ns1:Book/Authors)[1]'
;with XMLNAMESPACES ('MyNameSpace:V1' as ns1)
select
b.XmlData.value(
'@test'
, 'nvarchar(100)') as QueriedData
from Books b
where b.BookID = '1'
The above statement gave the following error.
XQuery [Books.XmlData.value()]: Top-level attribute nodes are not supported
Tried it as @test, instead of '@test'. And got the following error:
The argument 1 of the XML data type method "value" must be a string literal.
Tried it using 'sql:variable(@test)' and get this error:
XQuery [Books.XmlData.value()]: A string literal was expected
Tried it as 'sql:variable("@test")' and it shows the value in @test as QueriedData, which is wrong
Please tell me what am I missing here