SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询
这是来新公司写的第一篇文章,使用LEFT JOIN ON LIKE处理一下这种问题:

SQL视图代码如下:
CREATE View [dbo].[VI_SearchCN] AS
--搜索产品的文件
(
select upload.FileId as ID,upload.Name as Title,upload.Name as FileTxt,con.TypeId as TypeId,upload.Path as DownLoadPath, '文件' as SearchType,'' as CategoryId,'' as ParentCategoryId,upload.Sort,upload.CreateDate from Whir_Ext_Upload upload
left join
Whir_U_Content con
on ('*'+con.FileDownload+'*') like ('%*'+upload.Path+'*%')
where con.FileDownload!='' and con.IsDel=0 and con.TypeId=2
)
UNION ALL
--搜索产品
(
select con.Whir_U_Content_PId as ID,con.Title, '' as FileTxt, con.TypeId,'' as DownLoadPath,'产品' as SearchType,CategoryId,cat.ParentId as ParentCategoryId,con.Sort,con.CreateDate from Whir_U_Content Con
LEFT JOIN
Whir_U_Content_Category Cat
ON Cat.Whir_U_Content_Category_PId=con.CategoryId
where con.TypeId=2 and con.IsDel=0
)
UNION ALL
--新闻
select Whir_U_Content_PId as ID,Title,'' as FileTxt,TypeId,'' as DownLoadPath,'新闻' as SearchType,'' as CategoryId,'' as ParentCategoryId,Sort,CreateDate from Whir_U_Content where TypeId IN (13,14,15) and IsDel=0
UNION ALL
(
--文件下载COA
--select Whir_U_Content_PId as ID,Title,TypeId,'' as DownLoadPath,'COA' as SearchType,Sort,CreateDate from Whir_U_Content where TypeId=35 and IsDel=0
select upload.FileId as ID,con.Title,upload.Name as FileTxt,con.TypeId as TypeId,upload.Path as DownLoadPath, 'COA' as SearchType,'' as CategoryId,'' as ParentCategoryId,con.Sort,con.CreateDate from Whir_Ext_Upload upload
left join
Whir_U_Content con
on ('*'+con.FileDownload+'*') like ('%*'+upload.Path+'*%')
where con.FileDownload!='' and con.IsDel=0 and con.TypeId=35
) GO
前端代码如下:
<wtl:list ID="mylist1" needpage="true" sql="select ID,Title,Filetxt,TypeId,DownLoadPath,SearchType,CategoryId,ParentCategoryId,CreateDate from VI_SearchCN where Title LIKE '%{0}%' order by Sort desc,CreateDate desc" sql0="{@key,false}">
<wtl:if testtype="{$SearchType}" TestOperate="IN" testvalue="文件,COA">
<successTemplate>
<dd>
<a href="{$uploadpath}{$DownLoadPath,parent,1}" download="{$Title,parent,1}">
<span title="{$Title,70,parent,1}">【{$SearchType,parent,1}】{$Title,70,parent,1}</span>
<time>{$CreateDate,yyyy.MM.dd,parent,1}</time>
</a>
</dd>
</successTemplate>
</wtl:if>
<wtl:if testtype="{$SearchType}" TestOperate="Equals" testvalue="新闻">
<successTemplate>
<dd>
<a href="{$syspath}news/info_{$TypeId,parent,1}.aspx?itemid={$ID,parent,1}">
<span title="{$Title,70,parent,1}">【{$SearchType,parent,1}】{$Title,70,parent,1}</span>
<time>{$CreateDate,yyyy.MM.dd,parent,1}</time>
</a>
</dd>
</successTemplate>
</wtl:if>
<wtl:if testtype="{$SearchType}" TestOperate="Equals" testvalue="产品">
<successTemplate>
<dd>
<a href="{$syspath}cpzx/info_{$TypeId,parent,1}.aspx?itemid={$ID,parent,1}&lcid={$CategoryId,parent,1}&bcid={$ParentCategoryId,parent,1}">
<span title="{$Title,70,parent,1}">【{$SearchType,parent,1}】{$Title,70,parent,1}</span>
<time>{$CreateDate,yyyy.MM.dd,parent,1}</time>
</a>
</dd>
</successTemplate>
</wtl:if>
</wtl:list>
SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询的更多相关文章
- SQL Server 一列或多列重复数据的查询,删除
业务需求 最近给公司做一个小工具,把某个数据库(数据源)的数据导进另一个数据(目标数据库).要求导入目标数据库的数据不能出现重复.但情况是数据源本身就有重复的数据.所以要先清除数据源数据. 于是就把关 ...
- SQL Server 一列或多列重复数据的查询,删除(转载)
转载来源:https://www.cnblogs.com/sunxi/p/4572332.html 业务需求 最近给公司做一个小工具,把某个数据库(数据源)的数据导进另一个数据(目标数据库).要求导入 ...
- SQL Server中INNER JOIN与子查询IN的性能测试
这个月碰到几个人问我关于"SQL SERVER中INNER JOIN 与 IN两种写法的性能孰优孰劣?"这个问题.其实这个概括起来就是SQL Server中INNER JOIN与子 ...
- sql server几种Join的区别测试方法与union表的合并
/* sql server几种Join的区别测试方法 主要来介绍下Inner Join , Full Out Join , Cross Join , Left Join , Right Join的区别 ...
- sql server中如何修改视图中的数据?
sql server中如何修改视图中的数据? 我做个测试,视图的数据有标记字段时,如果是这种方式(0 as FlagState),是无法修改的 --创建视图语句 --- create view V_E ...
- SQL Server 2016五大优势挖掘企业用户数据价值
SQL Server 2016五大优势挖掘企业用户数据价值 转载自:http://soft.zdnet.com.cn/software_zone/2016/0318/3074442.shtml 3月1 ...
- SQL Server 2008空间数据应用系列五:数据表中使用空间数据类型
原文:SQL Server 2008空间数据应用系列五:数据表中使用空间数据类型 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Server 2008 R2调测 ...
- 从SQL Server到MySQL,近百亿数据量迁移实战
从SQL Server到MySQL,近百亿数据量迁移实战 狄敬超(3D) 2018-05-29 10:52:48 212 沪江成立于 2001 年,作为较早期的教育学习网站,当时技术选型范围并不大:J ...
- sql server 使用 partition by 分区函数 解决不连续数字查询问题
sql server表中的某一列数据为不一定连续的数字,但是需求上要求按照连续数字来分段显示,如:1,2,3,4,5,6,10,11,12,13, 会要求这样显示:1~6,10~13.下面介绍如何实现 ...
随机推荐
- 关于Cocos2d-x的数据存储
Cocos2d-x对数据的存储没有用到数据库,但是有用到一个类似数据库的小型数据库,就是数据存储.存储后的数据用XML的文件格式保存在C:\Users\Administrator\AppData\Lo ...
- Android actionbar 笔记
ActionBar是一种新増的导航栏功能,在Android 3.0之后加入到系统的API当中,它标识了用户当前操作界面的位置,并提供了额外的用户动作.界面导航等功能. 参考链接 https://dev ...
- 配置 -- PHPstorm+Xdebug断点调试PHP
运行环境: PHPSTORM版本 : 8.0.1 PHP版本 : 5.6.2 xdebug版本:php_xdebug-2.2.5-5.6-vc11-x86_64.dll ps : php版本和xdeb ...
- Nginx的启动与停止,重启
1.先确定nginx所在的文件位置 如: 重启 1.验证nginx配置文件是否正确 方法一:进入nginx安装目录sbin下,输入命令./nginx -t 2.重启Nginx服务 方法一:进入ngin ...
- while循环中,break,continue,return的差别
break 结束循环,跳出循环体: continue 结束本次循环.进行下次循环: return 跳出循环体所在的方法,相当于跳出循环体.
- windows 2008 r2 安装TabsStudio
windows 2008 r2 安装TabsStudio 办法如下: HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer.如果没有这个项,则新建这个项 ...
- foreach使用
1. 读取记录while($row=mysql_fetch_array($result)){$record[]=array( 'title'=>$row['title'], 'body'= ...
- PL/SQL如何调试Oracle存储过程
from:http://jingyan.baidu.com/article/3a2f7c2e144d2826aed61167.html 调试过程对找到一个存过的bug或错误是非常重要的,Oracle作 ...
- 浅析Linux内核同步机制
非常早之前就接触过同步这个概念了,可是一直都非常模糊.没有深入地学习了解过,最近有时间了,就花时间研习了一下<linux内核标准教程>和<深入linux设备驱动程序内核机制>这 ...
- swift -- 计步器CMPedometer的使用
最近公司接了个项目,是一款运动类型的APP,可以检测运动量(例如:步数,上下楼等).睡眠信息.速度等信息,因为以前粗略的了解过传感器方面的相关信息,知道主要是苹果设备内置的传感器在起作用,传感器的种类 ...