这是来新公司写的第一篇文章,使用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. e683. 设置打印的方向

    PrinterJob pjob = PrinterJob.getPrinterJob(); PageFormat pf = pjob.defaultPage(); if (portrait) { pf ...

  2. 转载: Erlang Socket解析二进制数据包

    转自:http://www.itkee.com/developer/detail-318.html 今天在家里闲来无事,实践了一下Erlang的Socket的功能.记录一下在过程中遇到的一些问题,以及 ...

  3. 【Java集合的详细研究5】Java中Array与ArrayList的主要区别

    1)精辟阐述:可以将 ArrayList想象成一种“会自动扩增容量的Array”. 2)Array([]):最高效:但是其容量固定且无法动态改变:     ArrayList:  容量可动态增长:但牺 ...

  4. ThinkPHP的ajaxReturn方法的使用

    ThinkPHP后端的代码如下: public function testAjax(){ $this->ajaxReturn(array('name'=>'z','age'=>18) ...

  5. php获取QQ头像并显示的方法

    鉴于此,我在想一个大众化的,比较简单的方法,我想到的是对于没有头像的朋友调用其QQ头像, 因为QQ现在至少是人手一个,所以只需要留言时填写QQ号,然后调用其头像,这样一来就方便多了. 首先是获取QQ的 ...

  6. Xcode 5: 将新项目同步到Svn上

    stackoverflow 两种办法,一是使用比较成熟的svn客户端,二是使用终端.以下为终端方法: 假设已经通过Xcode->Preferences->Accounts将reposito ...

  7. Resharper 安装以及破解

    首先进行软件安装 安装后 解压下载好的 文件 会得到如下: 打开序列号 会看到 然后  复制 %LocalAppData%\\JetBrains 路径 会得到进入当前JetBrains 文件夹 然后搜 ...

  8. 在懂得BREW接口的原理之后, 那么该知道BREW接口是如何声明和实现了

    参考:http://blog.csdn.net/peteryxk/article/details/1584514 首先介绍几个用到的宏定义: l         #define VTBL(iname) ...

  9. 关于Java 枚举类型的自定义属性

    package com.cpic.test;/** * 关于枚举类型自定义属性 * */public enum Provious { ANHUI("皖", 1),BAIJING(& ...

  10. Mac下,如何把项目托管到Github上(Github Desktop的使用)

    在上一篇中,详细讲解了使用X-code和终端配合上传代码的方法,这种方法比较传统,中间会有坑,英文看起来也费劲,不过Github官方提供了一个Mac版的客户端,如下图: