这是来新公司写的第一篇文章,使用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,'0' as CategoryId,'0' 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.CategoryIdwhere con.TypeId=2 and con.IsDel=0
)
UNION ALL
--新闻
select Whir_U_Content_PId as ID,Title,'' as FileTxt,TypeId,'' as DownLoadPath,'新闻' as SearchType,'0' as CategoryId,'0' 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,'0' as CategoryId,'0' 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>

转载于:https://www.cnblogs.com/kongxiaoshuang/p/8797119.html

SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询相关推荐

  1. 游标sql server_了解游标并将其替换为SQL Server中的JOIN

    游标sql server Relational database management systems including SQL Server are very good at processing ...

  2. 在SQL Server中为什么不建议使用Not In子查询

    原文:在SQL Server中为什么不建议使用Not In子查询 在SQL Server中,子查询可以分为相关子查询和无关子查询,对于无关子查询来说,Not In子句比较常见,但Not In潜在会带来 ...

  3. sql server中如何修改视图中的数据?

    原文地址::https://www.cnblogs.com/xielong/p/10516975.html 相关文章 1.MYSQL 视图的不可以更改数据----https://blog.csdn.n ...

  4. sql server使用convert来取得datetime日期数据

    sql server使用convert来取得datetime日期数据,以下实例包含各种日期格式的转换 语句及查询结果: Select CONVERT(varchar(100), GETDATE(), ...

  5. 云世界,一切如梦幻,数据也玩虚拟化。 SQL Server 2019 新特性系列一:数据虚拟化

    SQL Server 2019 新特性系列一:数据虚拟化 最新更新 SQL Server已经到了CTP2.2版本,主要更新了如下功能: 大数据集群:在大数据群集上使用 azure 数据工作室中的 sp ...

  6. Sql Server 中利用游标对table 的数据进行分组统计式输出…

    Sql Server 中利用游标对table 的数据进行分组统计式输出- Table Name: Tb_Color Create table Tb_Color(id int identity(1,1) ...

  7. SQL Server Always On可用性组中的数据同步

    This article describes the data synchronization process on SQL Server Always On Availability Groups ...

  8. 数组数据通过sql语句转为数据库表衔接到from或join后进行直接或关联查询

    Mybatis之数组数据通过sql语句转为数据库表衔接到from或join后进行直接或关联查询 外部数据 当前项目表格数据(表名:service_info) 将外部数据转为Table表格,与servi ...

  9. sql server如何直接在表中修改数据

    之前做项目一直用的是mysql和oracle,最近做的项目中客户使用的是sql server,之前不了解sql server,今天成功安装并且导入了数据库脚本.在做具体操作的时候,有些数据只需很小的修 ...

最新文章

  1. MySQL 数据库常用命令
  2. 用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联。
  3. 在CentOS7上配置SVN
  4. 如何隐藏storyboard中的top bar
  5. VMware vRealize Operations Manager SSRF漏洞(CVE-2021-21975、SSRF)
  6. Angular 内嵌视图、宿主视图
  7. 2021年Java基础面试题总结
  8. Java项目:Springboot校园报修管理系统
  9. 如何恢复SVN被删除文件、文件夹
  10. Laravel项目+Google验证器
  11. 传奇装备元素属性设置教程
  12. arduino惊喜盒子
  13. 是否对纯色背景的IDE感到乏味?那就让vscode背景变成你想要的样子
  14. 【大学英语四六级】四六级阅读高频词汇
  15. Android开发高性能之 (崩溃优化)
  16. 计算机组成原理扩展指令CLC实验报告,计算机组成原理实验设计
  17. 温州人不炒股票炒外汇 1亿美金爆炒出300亿交易量
  18. 在路由引入时应用路由策略 实验详解
  19. C语言结构体定义时候不能设置默认值(初始化)
  20. egret帧动画与粒子动画_动画基础知识:了解粒子

热门文章

  1. js实时获取窗口大小变化
  2. vue 同步加载_2019 前端面试题汇总(主要为 Vue)
  3. swing中怎么在原来图片的基础上切换第二张图片_摄影比赛原来是这么评出来的!照片点评与修图小赛第10期...
  4. 浙江义乌计算机中专学校,浙江义乌有没有中专学校?
  5. excel 单元格求和大于某个数后返回列号_Excel最常用的几个函数,我都帮你整理好了!...
  6. 2015蓝桥杯b组java_Java实现第十一届蓝桥杯JavaB组 省赛真题
  7. email邮件中 内嵌iframe_Python+Selenium执行结果,封装函数,用Python自动发送SMTP邮件...
  8. centos 测试get请求_11-CentOS7服务器搭建-ab压力测试
  9. 界址点圆圈怎么生成_技巧|CASS10.1的界址点圆圈如何变细?
  10. 修改LR自带的示例程序端口号,Cannot create GUI process-program not found