sql server 2008 - Extracting xml tag value for a given subtag-field combination -
the bzloans table has column named lnxml contains xml data/ table has loanid column loanid stored. sample data shown below in lnxml field in row loanid = 12345:
<loans> <schedule> <pid>4</pid> <amt>2100<damt> </schedule> <schedule> <pid>5</pid> <amt>1000</amt> </schedule> </loans>
the root tag loans , below schedule tag multiple subtags
i lookng query return value in amt tag when pid tag value , loanid value specified.
for example when pid specified 5 , loanid 12345, query should return, pid, loanid, amt 5.12345.1000
thanks in advance help.
declare @loanid int = 12345 declare @pid int = 5 select @pid pid, @loanid loanid, l.x.value('.', 'int') amt bzloans b cross apply b.lnxml.nodes('/loans/schedule[pid = sql:variable("@pid")]/amt') l(x) b.loanid = @loanid
Comments
Post a Comment