T-SQL XQUERY.VARIABLE

DECLARE @bn NVARCHAR(max) = '剑'
SELECT 
ArthurName,
Region,
CONVERT(NVARCHAR(max),BooksXML.query('
for $s in /books/book
let $n := data($s/@name)
let $p := concat($n,"-")
where $s/@name[contains(.,sql:variable("@bn"))]
order by $p
return $p')) AS BookList
FROM
[dbo].[Arthur]

ArthurNameRegionBookList
金庸香港书剑恩仇录- 碧血剑-
古龙台北三少爷的剑- 多情剑客无情剑- 流星·蝴蝶·剑- 浣花洗剑录-
梁羽生香港七剑下天山-

你可能感兴趣的:(variable)