久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

TSQL - 對多個值使用 LIKE 的部分匹配

TSQL - Partial Matching using LIKE for multiple values(TSQL - 對多個值使用 LIKE 的部分匹配)
本文介紹了TSQL - 對多個值使用 LIKE 的部分匹配的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想請教一下 SQL Server 中是否有任何函數允許我對值列表執行部分匹配?

I would like to seek your advice whether any function in SQL server that allow me to perform partial matching for a list of values ?

需要匹配的整個字符串將通過存儲過程傳入??.

The entire string that need to be matched will be passed in via store procedure.

在編寫自己的函數之前,我試圖找到其他替代方法,以逗號分隔字符串,然后在將數據返回給程序之前合并所有結果.

I am trying to find other alternative before writing my own function to split the string by comma and then union all the results before return the data to the program.

例如,我會將以下字符串傳入我的 TSQL

For example, I would pass in the following string into my TSQL

蘋果、橙子、梨

在我的 WHERE 子句中它應該匹配

in my WHERE clause it should match

select * from store where fruits like 'apple%'
select * from store where fruits like 'orange%'
select * from store where fruits like 'pear%'

我可以在單個 SQL 語句中實現上述結果而不是編寫函數來打破每個字符串嗎?

Can I achieve the above results in a single SQL statement rather than writing function to break each string ?

我表中的數據

apple red
apple green
orange sweet
orange sour
pear big
pear small

所以,當我傳入字符串 "apple,pear" 時,我需要返回

So, when I passed in the string "apple,pear" , I need to return

apple red
apple green
pear big
pear small

推薦答案

您可以將臨時表創建為

You can create a temp table as

'CREATE TABLE #Pattern (
      SearchItems VARCHAR(20)
    );'

旁注:確保檢查臨時表是否存在以避免錯誤.現在您可以將搜索詞插入到臨時表中

Side note: Make sure you check if the temp table exists to avoid errors. Now you can insert your search words to the temp table as

'INSERT 
    INTO #Pattern 
    VALUES 
        ('% APPLE %'),
        ('% ORANGE %'),
        ('% BANANA %');'

現在使用這個臨時表,使用 INNER JOIN 搜索你的表喜歡

Now using this temp table, Search your table using a INNER JOIN like

'SELECT *
 FROM Store
 INNER JOIN #Pattern
    ON Store.Fruits LIKE SearchItems
'

請注意,我盡量避免使用臨時表,但在這里它很方便,而且我使用此解決方案的情況對性能沒有要求.相反,它更容易保持不斷增長的 searchItems 的維護.

As a note, Temp Tables are something I try to avoid mostly, but here it comes handy, and the case I was using this solution was not demanding on performance. Rather it made it easier to keep the ever growing searchItems maintained.

希望這也適用于其他人.

Hope this works for others too.

這篇關于TSQL - 對多個值使用 LIKE 的部分匹配的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 欧美日韩国产中文 | 国产精品久久久久久久久免费相片 | 国产免费xxx | 午夜国产在线 | 日韩国产欧美 | 亚州国产 | 日皮视频免费 | 欧美一级片在线 | 欧美高清视频 | 午夜在线| 久久亚洲国产精品日日av夜夜 | 欧美综合一区二区三区 | 视频在线一区二区 | 97国产精品视频人人做人人爱 | 国产日产精品一区二区三区四区 | 亚洲精品一区中文字幕乱码 | 情侣酒店偷拍一区二区在线播放 | 精品国产色 | 久久av一区二区 | 亚洲视频欧美视频 | 免费精品视频在线观看 | 久久久噜噜噜久久中文字幕色伊伊 | 亚洲午夜久久久 | 欧美大片一区二区 | 日韩中文字幕一区二区 | 亚洲瑟瑟 | 国产成人精品区一区二区不卡 | 国产成人av一区二区三区 | 国内在线视频 | 免费三级网站 | 99精品欧美一区二区三区综合在线 | 国产精品自产拍在线观看蜜 | 美女露尿口视频 | 日韩av一区在线观看 | 久久国产精品久久久久久 | 欧美性jizz18性欧美 | 中国美女一级黄色片 | 欧洲精品在线观看 | 欧洲一区二区视频 | 色婷婷av99xx | 免费在线看黄 |