SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询
生活随笔
收集整理的這篇文章主要介紹了
SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
這是來新公司寫的第一篇文章,使用LEFT JOIN ON LIKE處理一下這種問題:
SQL視圖代碼如下:
CREATE View [dbo].[VI_SearchCN] AS --搜索產(chǎn)品的文件 ( 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 --搜索產(chǎn)品 ( select con.Whir_U_Content_PId as ID,con.Title, '' as FileTxt, con.TypeId,'' as DownLoadPath,'產(chǎn)品' 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="產(chǎn)品"><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>?
轉(zhuǎn)載于:https://www.cnblogs.com/kongxiaoshuang/p/8797119.html
總結(jié)
以上是生活随笔為你收集整理的SQL Server使用 LEFT JOIN ON LIKE进行数据关联查询的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【代码笔记】Web-HTML-列表
- 下一篇: python里的文件I/O