0
我試圖將xpath作爲參數傳遞給查詢。xml查詢變量
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'
上述說明給出了以下錯誤。
XQuery [Books.XmlData.value()]: Top-level attribute nodes are not supported
試過它作爲@test而不是'@test'。並得到了以下錯誤:
The argument 1 of the XML data type method "value" must be a string literal.
試了一下使用 'SQL:變量(@test)' 和得到這個錯誤:
XQuery [Books.XmlData.value()]: A string literal was expected
試圖爲「SQL:變量( 「@測試」) 「,它體現在@Test爲QueriedData,這是錯誤的價值
請告訴我,我在這裏缺少
您不能使用變量而不是xQuery表達式。你有一個選擇是動態構建和執行查詢,如[本答案](http://stackoverflow.com/a/14812275/569436)。 – 2013-03-04 13:38:16