这是来新公司写的第一篇文章,使用LEFT JOIN ON LIKE处理一下这种问题:

SQL视图代码如下:

  1. CREATE View [dbo].[VI_SearchCN] AS
  2. --搜索产品的文件
  3. (
  4. 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
  5. left join
  6. Whir_U_Content con
  7. on ('*'+con.FileDownload+'*') like ('%*'+upload.Path+'*%')
  8. where con.FileDownload!='' and con.IsDel=0 and con.TypeId=2
  9. )
  10. UNION ALL
  11. --搜索产品
  12. (
  13. 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
  14. LEFT JOIN
  15. Whir_U_Content_Category Cat
  16. ON Cat.Whir_U_Content_Category_PId=con.CategoryId
  17. where con.TypeId=2 and con.IsDel=0
  18. )
  19. UNION ALL
  20. --新闻
  21. 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
  22. UNION ALL
  23. (
  24. --文件下载COA
  25. --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
  26. 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
  27. left join
  28. Whir_U_Content con
  29. on ('*'+con.FileDownload+'*') like ('%*'+upload.Path+'*%')
  30. where con.FileDownload!='' and con.IsDel=0 and con.TypeId=35
  31. )
  32.  
  33. GO

前端代码如下:

  1. <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}">
  2. <wtl:if testtype="{$SearchType}" TestOperate="IN" testvalue="文件,COA">
  3. <successTemplate>
  4. <dd>
  5. <a href="{$uploadpath}{$DownLoadPath,parent,1}" download="{$Title,parent,1}">
  6. <span title="{$Title,70,parent,1}">【{$SearchType,parent,1}】{$Title,70,parent,1}</span>
  7. <time>{$CreateDate,yyyy.MM.dd,parent,1}</time>
  8. </a>
  9. </dd>
  10. </successTemplate>
  11. </wtl:if>
  12. <wtl:if testtype="{$SearchType}" TestOperate="Equals" testvalue="新闻">
  13. <successTemplate>
  14. <dd>
  15. <a href="{$syspath}news/info_{$TypeId,parent,1}.aspx?itemid={$ID,parent,1}">
  16. <span title="{$Title,70,parent,1}">【{$SearchType,parent,1}】{$Title,70,parent,1}</span>
  17. <time>{$CreateDate,yyyy.MM.dd,parent,1}</time>
  18. </a>
  19. </dd>
  20. </successTemplate>
  21. </wtl:if>
  22. <wtl:if testtype="{$SearchType}" TestOperate="Equals" testvalue="产品">
  23. <successTemplate>
  24. <dd>
  25. <a href="{$syspath}cpzx/info_{$TypeId,parent,1}.aspx?itemid={$ID,parent,1}&lcid={$CategoryId,parent,1}&bcid={$ParentCategoryId,parent,1}">
  26. <span title="{$Title,70,parent,1}">【{$SearchType,parent,1}】{$Title,70,parent,1}</span>
  27. <time>{$CreateDate,yyyy.MM.dd,parent,1}</time>
  28. </a>
  29. </dd>
  30. </successTemplate>
  31. </wtl:if>
  32. </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. C++字符串转化为数字的库函数

    原文链接:http://blog.csdn.net/tsinfeng/article/details/5844838 1.atoi 功 能:把一字符串转换为整数 用 法:int atoi(const ...

  2. asp.net mvc中用angularJs写的增删改查的demo。初学者,求指点。。

    直接给个代码下载链接.... http://pan.baidu.com/s/1FfVgq 本人刚刚学习angularJs,感觉双向数据绑定蛮爽的... 之前的代码存在点问题,已修复

  3. c++ json cpp

    一 编译链接 1 在相应官网下载jsoncpp 2 解压得到jsoncpp-src-0.5.0文件 3 打开jsoncpp-src-0.5.0 -> makefiles -> vs71 - ...

  4. 第二章 入门(MyBatis)

    本章将会以简略的步骤告诉你如何安装和创建 MyBatis-Spring,并构建一个简单的数据访问事务性的应用程序. Installation 要使用 MyBatis-Spring 模块,你只需要包含 ...

  5. Unity 如何高效的解析数据

    昨天和朋友聊天时,他遇到这么一个问题:现在有按照一定格式的数据,例如:#code==text 此处是注释100==确定101==取消key==value 这么个格式的,说白了就是怎样解析这些固定格式字 ...

  6. js判断用户关闭页面或浏览器

    <html><head><meta http-equiv="Content-Type" content="text/html; charse ...

  7. mysql中,如何查看数据库中当前可用的校勘?字符集默认的collation?

    需求描述: mysql的字符集在使用的过程中会有一些规则,这些规则就组成了校勘, 也就是通过什么规则做什么事,比如,如何比较两个字符的大小,后台都是有一些 规则,这些规则就是校勘的一部分. 那么,查看 ...

  8. tiny6410的linux操作系统实验开发

    ---恢复内容开始--- 1.前期由于2440 的4.3寸屏太小.后来修改程序准备在tiny6410增强版的S70屏上用.但是前期移植再用yaffs的文件系统,但是6410是(MLC)的磁盘,根本就不 ...

  9. 给IT同学推荐这15个不错的学习网站,收藏起来慢慢看吧

    1.学堂在线:http://www.xuetangx.com 目前,学堂在线运行了包括包括清华大学.北京大学.复旦大学.斯坦福大学.麻省理工学院.加州大学伯克利分校等国内外几十所顶尖高校的优质课程.在 ...

  10. UART简介

    经常遇到初学者,对单片机串行通讯出了问题不知道如何办的情况.其实最有效的调试方法是用示波器观察收发数据的波形.通过观察波形可以确定以下情况: 1.数据是否接收或发送: 2.数据是否正确: 3.波特率是 ...