这是来新公司写的第一篇文章,使用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. IOS内购支付server验证模式

    IOS 内购支付两种模式: 内置模式 server模式 内置模式的流程: app从app store 获取产品信息 用户选择须要购买的产品 app发送支付请求到app store app store ...

  2. perl 实现ascall 码转换

    今天需要在perl中实现一个字母表, 总不能把26个字母一个一个写出来,于是查资料,可以利用ascii码转换把数字转换成对应的字母 chr函数可以利用ascii编码把数字转换成对应的字母 perl - ...

  3. php将汉字转换为拼音和得到词语首字母(一)

    <?php /** * 修复二分法查找方法 * 汉字拼音首字母工具类 * 注: 英文的字串:不变返回(包括数字) eg .abc123 => abc123 * 中文字符串:返回拼音首字符 ...

  4. htaccess正则规则学习笔记整理

    # —— 位于行首时表示注释. [F] —— Forbidden(禁止): 命令服务器返回 403 Forbidden错误给用户浏览器 [L] —— Last rule(最后一条规则): 告诉服务器在 ...

  5. oracle中REF Cursor用法

    from:http://www.111cn.net/database/Oracle/42873.htm 1,什么是 REF游标 ? 动态关联结果集的临时对象.即在运行的时候动态决定执行查询. 2,RE ...

  6. [Android系列—] 4. 加入操作栏(Action Bar)

    前言 操作栏是最重要的设计元素之中的一个,使用它来实现你的应用程序活动.通过提供多种用户界面功能, 使应用程序高速和其它的Andorid应用程序一致, 以便被用户熟悉和接受. 主要功能包括: 1. 标 ...

  7. 分布式消息队列RocketMQ与Kafka架构上的巨大差异之1 -- 为什么RocketMQ要去除ZK依赖?

    我们知道,在早期的RocketMQ版本中,是有依赖ZK的.而现在的版本中,是去掉了对ZK的依赖,转而使用自己开发的NameSrv. 并且这个NameSrv是无状态的,你可以随意的部署多台,其代码也非常 ...

  8. Android开发之--常用颜色值

    <?xml version="1.0" encoding="utf-8" ?> <resources> <color name=& ...

  9. swift开发之 -- ? 和 ! 的作用

    记录下这个知识点: 一般我们在一下两种情况会遇到 ? 和 !的使用 1,声明变量时 var number:Int? var str:String? 2,在对变量进行操作时 number?.hasVal ...

  10. python文件和目录操作方法大全(含实例)【python】

    转自:http://www.jb51.net/article/48001.htm 一.python中对文件.文件夹操作时经常用到的os模块和shutil模块常用方法. 1.得到当前工作目录,即当前Py ...