0
好吧,我一直在爲此亂搞一段時間,但似乎無法使其發揮作用。那麼,或者它是不可能的剝離XML字符串中的標籤並將其用作別名
鑑於以下T-SQL我想剝離<>標記並使用裏面的內容作爲別名。可能?我正在考慮嵌套替換剝離它,但不知道如何使用結果作爲別名。整個目標是在SET語句中定義html標記,並讓它自動填充表變量中的別名和列指示符。如果有一個更好/更簡單的方法,不像xpath那樣涉及,我是開放的。
Use Database
DECLARE @First VARCHAR(15), @Second VARCHAR(15),@XMLTag varchar(15)
SET @First = '<InstrumentID>'
SET @Second = '</InstrumentID>'
SET @XMLTag = Replace(Replace,@first,'<',''),@first,'>','')
select *
from
(
SELECT out_interface_id, msg_id ,
SUBSTRING(xml_msg, CHARINDEX(@First, xml_msg) + LEN(@First),
CHARINDEX(@Second, xml_msg) -
CHARINDEX(@First, xml_msg) -
LEN(@First)) as @XMLTag,
msg_type, xml_msg, CAST(xml_msg AS XML) as [Quick_XML],
date_received,status, last_modified, environment,
transaction_closed_date
from Table1 with (nolock)
where msg_type in ('BALMIS','ACCTV21')
and date_received >= CAST(GETDATE() -1 as DATE)
and date_received < CAST(GETDATE() as DATE)
) x
where [email protected] = 'ABC123'
order by date_received desc
@XMLtag的assign語句存在語法錯誤。考慮修復它。 – AXMIM
要使別名正常工作,您需要動態SQL – AXMIM