SQL Federated Query and XML parsing example _mssql

Source: Internet
Author: User

SQL Federated Query and XML parsing instance

Here is an example of how to implement this feature:

(select A.ebillno, A.empname, A.applydate, B.hs_name, replace (A.summary,char (), '), char (), ') as SUMMARY, Cast (C.xmldata as XML). Value (' (/list/item/no/text ()) [1] ', ' NVARCHAR ') as No, cast (C.xmldata as XML). Value (' (/list /item/zje/text ()) [1] ', ' NVARCHAR ') as Zje, cast (C.xmldata as XML). Value (' (/list/item/yfje/text ()) [1] ', ' NVARCHAR (a) as Yfje, cast (C.xmldata as XML). Value (' (/list/item/bcje/text ()) [1] ', ' NVARCHAR ') as Bcje, cast (C.xmldata as XML). Value (' (/list/item/url/text ()) [1] ', ' NVARCHAR ') as URL, cast (C.xmldata as XML). Value (' (/list/item/remark/ Text ()) [1] ', ' NVARCHAR ') as BZ, cast (P.xmldata as XML). Value (' (/newdataset/table1/username/text ()) [1] ', ' NVARCHAR ') as Skrxm, (' http://...? Sid=3&mid=7281&pid= ' +a.pid as Bxdljdz from Ex_bill as a left join Ex_system_cfg as B on (a.billsystemid=b.hs_id a nd a.datasystemid=b.system_name) LEFT join (SELECT * FROM [10.2.3.39]. AspireworkFlow.dbo.RepeaingTable) as C on (c.keyword= ' URL ' and c.processid=a. PID) LEFT JOIN (SELECT * FROM [10.2.3.39]. AspireworkFlow.dbo.RepeaingTable) as D on (d.keyword= ' fkxx_new ' and d.processid=a.pid or d.keyword= ' fkxx ' and D. Processid=a.pid) LEFT JOIN (SELECT * to Ex_billextension) as P on A.billno=p.bill_no where applyempid= ' Zhongxun ' and a. Ebillno is not null and status>5 and status isn't in (200,100,7000) and a.applydate> ' 2011-01-01 ' and a.ht= ' are ' and cast ' ( D.xmldata as XML). Value (' (/list/item/skrxm/text ()) [1] ', ' NVARCHAR () ') is null union (select E.ebillno, E.empname, E. Applydate, F.hs_name, replace (replace (E.summary,char (), '), char (), ') as SUMMARY, cast (G.xmldata as XML). Value (' ( /list/item/no/text ()) [1] ', ' NVARCHAR ') as No, cast (G.xmldata as XML). Value (' (/list/item/zje/text ()) [1] ', ' NVARCHAR ") as Zje, cast (G.xmldata as XML). Value (' (/list/item/yfje/text ()) [1] ', ' NVARCHAR ') as Yfje, cast (g. XMLData as XML). Value (' (/list/item/bcje/text ()) [1] ', ' NVARCHAR ') as Bcje, cast (G.xmldata as XML). Value (' (/list/ Item/url/text ()) [1] ', ' NVARCHAR) as URL, cast (G.xmldata as XML). Value (' (/list/item/remark/text ()) [1] ', ' NVARCHAR ') as BZ, cast (H. XMLData as XML). Value (' (/list/item/skrxm/text ()) [1] ', ' NVARCHAR ') as Skrxm, (' http://...? Sid=3&mid=7281&pid= ' +e.pid as Bxdljdz from Ex_bill as e-left join Ex_system_cfg as F on (e.billsystemid=f.hs_id a nd e.datasystemid=f.system_name) LEFT join (SELECT * FROM [10.2.3.39]. AspireworkFlow.dbo.RepeaingTable) as G on (g.keyword= ' URLs ' and g.processid=e.pid) left join (SELECT * FROM [10.2.3.39]. AspireworkFlow.dbo.RepeaingTable) as h on (h.keyword= ' fkxx_new ' and h.processid=e.pid or h.keyword= ' fkxx ' and H. processid=e.pid) where applyempid= ' Zhongxun ' and e.ebillno are not null and status>5 and-Status not in (200,100,7000) a D e.applydate> ' 2011-01-01 ' and e.ht= ' are ' and cast (H.xmldata as XML). Value (' (/list/item/skrxm/text ()) [1] ', ' NVARCHAR ( ) is not NULL)

When writing SQL, the difficulty is not in the SQL itself, but logically, when you write this SQL, it's not that hard to find logic.

is to use the Union to put the two groups of query out of the table into one inside

Thank you for reading, I hope to help you, thank you for your support for this site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.