sql查询过程解析(SQL 联合查询与XML解析实例详解)
类别:数据库 浏览量:1928
时间:2022-01-25 00:04:05 sql查询过程解析
SQL 联合查询与XML解析实例详解SQL 联合查询与XML解析实例
这里举例说明如何实现该功能:
(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=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 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=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 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的时候,难点不在于SQL本身,而在于逻辑上,当写出这个SQL以后,发现逻辑也没有那么难了。
就是采用Union把两组都查询出来的表放到一个里面
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
您可能感兴趣
- sql数据库查询优化(数据库SQL语句优化总结收藏)
- sqlserver语句显示表字段(SQL Server查找表名或列名中包含空格的表和列实例代码)
- sql解析器配置(sql字段解析器的实现示例)
- mysql定期备份(Mysql5.7定时备份的实现)
- 循环查询sql server(SQL Server 树形表非循环递归查询的实例详解)
- mysql密码设置(mysql密码中有特殊字符&在命令行下登录的操作)
- mysql什么是慢查询(MySQL慢查询的坑)
- sql转字符串函数(sql中的常用的字符串处理函数大全)
- sql怎么设置排列(SQL写法--行行比较)
- docker怎样安装mysql8(docker-compose安装db2数据库操作)
- 宝塔mysql怎么设置优化(宝塔面板mysql内存占用高如何优化)
- mysql设置updatetime自动更新(mysql 实现添加时间自动添加更新时间自动更新操作)
- mysql查询很慢怎么回事(MySQL Like模糊查询速度太慢如何解决)
- SQL Server表误删记录如何恢复
- mysql插入数据错误代码(教你解决往mysql数据库中存入汉字报错的方法)
- mysql8.0.18.0安装详细教程(mysql 8.0.22 下载安装配置方法图文教程)
- 白蓝色穿搭(白蓝色衣服配什么裤子)
- 天空是什么颜色(天空是什么颜色的英语)
- 高马尾扎发(高马尾扎发教程视频)
- 这里输入关键词(请手动输入关键词)
- 小说 顾瑾岚拿出一套飞行棋,别说你连飞行棋都不会哦(顾瑾岚拿出一套飞行棋)
- 金品公司 界界乐中秋限定飞行棋礼盒 露营藤篮礼盒全新上市(界界乐中秋限定飞行棋礼盒)
热门推荐
- 数据库mysql基本知识(深入理解r2dbc在mysql中的使用)
- docker harbor 配置中央仓库(Docker Gitlab+Jenkins+Harbor构建持久化平台操作)
- 阿里云注册域名ddns怎么写(如何通过阿里云实现动态域名解析DDNS的方法)
- mysql的存储方法(MySQL中的binary类型使用操作)
- SqlServer生成连续数字根据指定的数字操作(SqlServer生成连续数字根据指定的数字操作)
- vue 富文本图片上传(vue.js云存储实现图片上传功能)
- python操作json库(Python将json文件写入ES数据库的方法)
- mysql 高级查询语法(MySQL查询语句进阶知识集锦)
- 怎么搭建个人云服务器(怎么使用云服务器搭建个人网站?)
- MVC过滤器的用法
排行榜
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9