在等待您的回复时,这里是基于一些假设的答案。
顺便说一句,您的 XML 格式不正确。我不得不修复它。
SQL
-- DDL and sample data population, start
DECLARE @tbl TABLE (ID INT IDENTITY PRIMARY KEY, payload XML);
INSERT INTO @tbl (payload)
VALUES
(N'<FL>
<Head>
<TP>Nine11</TP>
<RB>Test</RB>
</Head>
</FL>');
-- DDL and sample data population, end
DECLARE @rb VARCHAR(20) = 'Test';
SELECT c.value('(TP/text())[1]', 'VARCHAR(30)') AS tp
, c.value('(RB/text())[1]', 'VARCHAR(30)') AS rb
FROM @tbl AS tbl
CROSS APPLY tbl.payload.nodes('/FL/Head[RB=sql:variable("@rb")]') AS t(c);
输出
+--------+------+
| tp | rb |
+--------+------+
| Nine11 | Test |
+--------+------+