这是来新公司写的第一篇文章,使用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进行数据关联查询的更多相关文章

  1. SQL Server 一列或多列重复数据的查询,删除

    业务需求 最近给公司做一个小工具,把某个数据库(数据源)的数据导进另一个数据(目标数据库).要求导入目标数据库的数据不能出现重复.但情况是数据源本身就有重复的数据.所以要先清除数据源数据. 于是就把关 ...

  2. SQL Server 一列或多列重复数据的查询,删除(转载)

    转载来源:https://www.cnblogs.com/sunxi/p/4572332.html 业务需求 最近给公司做一个小工具,把某个数据库(数据源)的数据导进另一个数据(目标数据库).要求导入 ...

  3. SQL Server中INNER JOIN与子查询IN的性能测试

    这个月碰到几个人问我关于"SQL SERVER中INNER JOIN 与 IN两种写法的性能孰优孰劣?"这个问题.其实这个概括起来就是SQL Server中INNER JOIN与子 ...

  4. sql server几种Join的区别测试方法与union表的合并

    /* sql server几种Join的区别测试方法 主要来介绍下Inner Join , Full Out Join , Cross Join , Left Join , Right Join的区别 ...

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

    sql server中如何修改视图中的数据? 我做个测试,视图的数据有标记字段时,如果是这种方式(0 as FlagState),是无法修改的 --创建视图语句 --- create view V_E ...

  6. SQL Server 2016五大优势挖掘企业用户数据价值

    SQL Server 2016五大优势挖掘企业用户数据价值 转载自:http://soft.zdnet.com.cn/software_zone/2016/0318/3074442.shtml 3月1 ...

  7. SQL Server 2008空间数据应用系列五:数据表中使用空间数据类型

    原文:SQL Server 2008空间数据应用系列五:数据表中使用空间数据类型 友情提示,您阅读本篇博文的先决条件如下: 1.本文示例基于Microsoft SQL Server 2008 R2调测 ...

  8. 从SQL Server到MySQL,近百亿数据量迁移实战

    从SQL Server到MySQL,近百亿数据量迁移实战 狄敬超(3D) 2018-05-29 10:52:48 212 沪江成立于 2001 年,作为较早期的教育学习网站,当时技术选型范围并不大:J ...

  9. sql server 使用 partition by 分区函数 解决不连续数字查询问题

    sql server表中的某一列数据为不一定连续的数字,但是需求上要求按照连续数字来分段显示,如:1,2,3,4,5,6,10,11,12,13, 会要求这样显示:1~6,10~13.下面介绍如何实现 ...

随机推荐

  1. Spring 父子容器

    必须要说的是,父子容器是通过设置形成的关系. 容器实现了 ConfigurableApplicationContext 或 ConfigurableBeanFactory 接口,这两个接口中分别有se ...

  2. windows 解压缩命令

    首先安装winrar 压缩: 命令:start winrar a test test.py 解压: 命令:start winrar x -y test.rar F:\batShell\test\tes ...

  3. 【转】C# URL短地址压缩算法及短网址原理解析

    这篇文章主要介绍了C# URL短地址压缩算法及短网址原理解析,本文重点给出了算法代码,需要的朋友可以参考下 短网址应用已经在全国各大微博上开始流行了起来.例如QQ微博的url.cn,新郎的sinaur ...

  4. Floyd算法实例

    ~ 当k=0时,我们关注的是邻接矩阵的第0行和第0列,即顶点0的入边和出边: 考察矩阵中其他元素,如果元素D[i][j]向第0行和第0列的投影D[0][j]和D[i][0]都有值,就说明原图中从 i ...

  5. Discuz论坛post登录C#源码

    总结: loginhash formhash  表单参数 seccode 参数最重要 全局 的 获取验证码 判断验证码 到最后提交登录 它都有存在 ,seccode==idhash COOKIE自动维 ...

  6. MySQL(二)之服务管理与配置文件修改和连接MySQL

    上一篇给大家介绍了怎么在linux和windows中安装mysql,本来是可以放在首页的,但是博客园说“安装配置类文件”不让放在首页.接下来给大家介绍一下在linux和windows下MySQL的一下 ...

  7. 帝国cms目录结构

    / 系统根目录├d/         附件和数据存放目录 (data) │├file/    附件存放目录 │├js/       JS调用生成目录 │└txt/        内容存文本存放目录 ├ ...

  8. mysql数据库binary log中的事件到底是什么?

    需求描述: 最近看mysql备份恢复的时候,基于时间点恢复,提到了binary log中存的是"事件" 那么到底什么是事件呢 概念解释: binary log中存的是事件(even ...

  9. brew 接口的原理

    请查看相关文档的第9章 该文档可以csdn silentjesse帐号下的资源去下载 http://download.csdn.net/detail/silentjesse/5859077

  10. 【spring教程之中的一个】创建一个最简单的spring样例

    1.首先spring的主要思想,就是依赖注入.简单来说.就是不须要手动new对象,而这些对象由spring容器统一进行管理. 2.样例结构 如上图所看到的,採用的是mavenproject. 2.po ...