主頁(yè) > 知識(shí)庫(kù) > SQL 聯(lián)合查詢與XML解析實(shí)例詳解

SQL 聯(lián)合查詢與XML解析實(shí)例詳解

熱門標(biāo)簽:互聯(lián)網(wǎng)電話外呼系統(tǒng) 千呼電話機(jī)器人可以試用嗎 零成本地圖標(biāo)注賺錢 400電話辦理泰安 安卡拉地圖標(biāo)注app 我要地圖標(biāo)注數(shù)量有限制嗎 電銷需要外呼系統(tǒng)嗎 電話機(jī)器人怎么代理商 家庭農(nóng)場(chǎng)地圖標(biāo)注名稱怎樣起名

SQL 聯(lián)合查詢與XML解析實(shí)例

          這里舉例說(shuō)明如何實(shí)現(xiàn)該功能:

(select a.EBILLNO,
a.EMPNAME,
a.APPLYDATE,
b.HS_NAME,
replace(replace(a.SUMMARY,char(10), ''),char(13),'') as SUMMARY,
cast(c.XmlData as XML).value('(/List/item/No/text())[1]','NVARCHAR(300)') as No,
cast(c.XmlData as XML).value('(/List/item/zje/text())[1]','NVARCHAR(300)') as zje,
cast(c.XmlData as XML).value('(/List/item/yfje/text())[1]','NVARCHAR(300)') as yfje,
cast(c.XMLData as XML).value('(/List/item/bcje/text())[1]','NVARCHAR(300)') as bcje,
cast(c.XMLData as XML).value('(/List/item/URL/text())[1]','NVARCHAR(300)') as URL,
cast(c.XMLData as XML).value('(/List/item/Remark/text())[1]','NVARCHAR(300)') as BZ,
cast(p.XMLData as XML).value('(/NewDataSet/Table1/UserName/text())[1]','NVARCHAR(500)') as SKRXM,
('http://……?sid=3mid=7281PID='+a.PID) as bxdljdz
from Ex_Bill as a 
left join Ex_System_Cfg as b on(a.BILLSYSTEMID=b.HS_ID and 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 * from EX_BillExtension) as p on a.BILLNO=p.BILL_NO

where applyempid='zhongxun' and a.EBILLNO is not null
and status>5 and status not in(200,100,7000)
and a.APPLYDATE>'2011-01-01'
and a.HT='是'
and cast(d.XMLData as XML).value('(/List/item/SKRXM/text())[1]','NVARCHAR(300)') is null) 
union
(select e.EBILLNO,
e.EMPNAME,
e.APPLYDATE,
f.HS_NAME,
replace(replace(e.SUMMARY,char(10), ''),char(13),'') as SUMMARY,
cast(g.XmlData as XML).value('(/List/item/No/text())[1]','NVARCHAR(300)') as No,
cast(g.XmlData as XML).value('(/List/item/zje/text())[1]','NVARCHAR(300)') as zje,
cast(g.XmlData as XML).value('(/List/item/yfje/text())[1]','NVARCHAR(300)') as yfje,
cast(g.XMLData as XML).value('(/List/item/bcje/text())[1]','NVARCHAR(300)') as bcje,
cast(g.XMLData as XML).value('(/List/item/URL/text())[1]','NVARCHAR(300)') as URL,
cast(g.XMLData as XML).value('(/List/item/Remark/text())[1]','NVARCHAR(300)') as BZ,
cast(h.XMLData as XML).value('(/List/item/SKRXM/text())[1]','NVARCHAR(300)') as SKRXM,
('http://……?sid=3mid=7281PID='+e.PID) as bxdljdz
from Ex_Bill as e 
left join Ex_System_Cfg as f on(e.BILLSYSTEMID=f.HS_ID and e.DATASYSTEMID=f.SYSTEM_NAME)
left join (select * from [10.2.3.39].AspireworkFlow.dbo.RepeaingTable) as g on (g.Keyword='URL' 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 is not null
and status>5 and status not in(200,100,7000)
and e.APPLYDATE>'2011-01-01'
and e.HT='是'
and cast(h.XMLData as XML).value('(/List/item/SKRXM/text())[1]','NVARCHAR(300)') is not null)

在寫SQL的時(shí)候,難點(diǎn)不在于SQL本身,而在于邏輯上,當(dāng)寫出這個(gè)SQL以后,發(fā)現(xiàn)邏輯也沒(méi)有那么難了。

就是采用Union把兩組都查詢出來(lái)的表放到一個(gè)里面

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

您可能感興趣的文章:
  • 詳解Mysql多表聯(lián)合查詢效率分析及優(yōu)化
  • 對(duì)MySQL幾種聯(lián)合查詢的通俗解釋
  • Mysql聯(lián)合查詢UNION和UNION ALL的使用介紹
  • Mysql聯(lián)合查詢UNION和Order by同時(shí)使用報(bào)錯(cuò)問(wèn)題的解決辦法
  • 深入sql多表差異化聯(lián)合查詢的問(wèn)題詳解
  • mysql多表聯(lián)合查詢返回一張表的內(nèi)容實(shí)現(xiàn)代碼
  • SQL語(yǔ)言查詢基礎(chǔ):連接查詢 聯(lián)合查詢 代碼

標(biāo)簽:濱州 東營(yíng) 大同 文山 新鄉(xiāng) 池州 來(lái)賓 黃山

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《SQL 聯(lián)合查詢與XML解析實(shí)例詳解》,本文關(guān)鍵詞  SQL,聯(lián)合,查詢,與,XML,解析,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《SQL 聯(lián)合查詢與XML解析實(shí)例詳解》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于SQL 聯(lián)合查詢與XML解析實(shí)例詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章