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

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

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

問題描述

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

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.

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

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 子句中它應(yīng)該匹配

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 語句中實現(xiàn)上述結(jié)果而不是編寫函數(shù)來打破每個字符串嗎?

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

我表中的數(shù)據(jù)

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

所以,當(dāng)我傳入字符串 "apple,pear" 時,我需要返回

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

apple red
apple green
pear big
pear small

推薦答案

您可以將臨時表創(chuàng)建為

You can create a temp table as

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

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

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 %');'

現(xiàn)在使用這個臨時表,使用 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 的維護(hù).

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.

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

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

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標(biāo)記轉(zhuǎn)換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計算值創(chuàng)建計算值)
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屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 日韩中文字幕在线播放 | 97精品视频在线 | av在线电影网 | 免费看国产a | 人人爱干 | 中文字幕亚洲欧美日韩在线不卡 | 国产成人区 | 中文字幕在线第二页 | 亚洲欧美激情国产综合久久久 | 黄色片免费看 | 性高湖久久久久久久久3小时 | 久久99精品国产99久久6男男 | 亚洲国产一区视频 | 自拍偷拍中文字幕 | 久久国产成人午夜av影院武则天 | 国产高清在线精品一区二区三区 | 国产一区不卡 | 国产精品精品视频一区二区三区 | 99精品国自产在线 | 日韩精品一区二区久久 | 欧美日韩久久久 | 欧美亚洲国产成人 | 欧美日韩国产一区二区三区 | 欧美一级艳情片免费观看 | 久久久久久久久久爱 | 亚洲在线一区二区 | 在线看91| av在线播放一区二区 | 一区二区高清不卡 | 啪啪精品 | www.黄色在线观看 | 国产精品日韩 | 国产男女视频网站 | 99热首页 | 夜夜夜操 | 亚洲最大福利网 | 五月天婷婷久久 | 看黄在线 | 性色av网站 | 亚洲成人av在线 | 99精品一区二区三区 |