SQL Server and xml -
i pass xml varchar
scalar function in sql server:
<screenerinfo> <extendexpiryinfo> <extendexpiry> <actionon>2015-05-19 13:31:40.019</actionon> <comments>nikilesh</comments> <approvalstatus>ee</approvalstatus> <newexpirydate>2015/06/25 12:28:59pm</newexpirydate> </extendexpiry> </extendexpiryinfo> </screenerinfo>
i want retrieve every thing between comment tag , separate each comment comma store in varchar
variable , return how can achieve this......
for eg...
nikilesh,manish,done,rejected...
how possible?
i don't know, "manish" or "done" or "rejected" comes from, asking content of comments-node i'd assume, there more nodes these phrases in comments-node. in following example copied example node 3 times , changed content of comments. if paste empty query window you'll get:
result: nikilesh, manish, done declare @xml xml= '<root> <screenerinfo> <extendexpiryinfo> <extendexpiry> <actionon>2015-05-19 13:31:40.019</actionon> <comments>nikilesh</comments> <approvalstatus>ee</approvalstatus> <newexpirydate>2015/06/25 12:28:59pm</newexpirydate> </extendexpiry> </extendexpiryinfo> </screenerinfo> <screenerinfo> <extendexpiryinfo> <extendexpiry> <actionon>2015-05-19 13:31:40.019</actionon> <comments>manish</comments> <approvalstatus>ee</approvalstatus> <newexpirydate>2015/06/25 12:28:59pm</newexpirydate> </extendexpiry> </extendexpiryinfo> </screenerinfo> <screenerinfo> <extendexpiryinfo> <extendexpiry> <actionon>2015-05-19 13:31:40.019</actionon> <comments>done</comments> <approvalstatus>ee</approvalstatus> <newexpirydate>2015/06/25 12:28:59pm</newexpirydate> </extendexpiry> </extendexpiryinfo> </screenerinfo> </root>'; select stuff( ( select ', ' + screener.info.value('(extendexpiryinfo/extendexpiry/comments)[1]','varchar(max)') @xml.nodes('/root/screenerinfo') screener(info) xml path('') ),1,2,'')
if need else, please clearify question...
Comments
Post a Comment