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

TSQL - 對(duì)多個(gè)值使用 LIKE 的部分匹配

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

問(wèn)題描述

我想請(qǐng)教一下 SQL Server 中是否有任何函數(shù)允許我對(duì)值列表執(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 ?

需要匹配的整個(gè)字符串將通過(guò)存儲(chǔ)過(guò)程傳入??.

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

在編寫(xiě)自己的函數(shù)之前,我試圖找到其他替代方法,以逗號(hào)分隔字符串,然后在將數(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.

例如,我會(huì)將以下字符串傳入我的 TSQL

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

蘋(píng)果、橙子、梨

在我的 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%'

我可以在單個(gè) SQL 語(yǔ)句中實(shí)現(xiàn)上述結(jié)果而不是編寫(xiě)函數(shù)來(lái)打破每個(gè)字符串嗎?

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" 時(shí),我需要返回

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

apple red
apple green
pear big
pear small

推薦答案

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

You can create a temp table as

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

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

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)在使用這個(gè)臨時(shí)表,使用 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
'

請(qǐng)注意,我盡量避免使用臨時(shí)表,但在這里它很方便,而且我使用此解決方案的情況對(duì)性能沒(méi)有要求.相反,它更容易保持不斷增長(zhǎng)的 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 - 對(duì)多個(gè)值使用 LIKE 的部分匹配的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
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?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對(duì)?) - IT屋-程序員軟件開(kāi)發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(hào)(問(wèn)題和答案的組合))
主站蜘蛛池模板: 国产亚洲精品久久午夜玫瑰园 | 国产大毛片 | 国产电影一区二区在线观看 | 久久国产精品久久久久 | 青青草原综合久久大伊人精品 | 亚洲一区二区在线电影 | 欧美激情在线精品一区二区三区 | 一区二区三区精品视频 | 成人在线视频免费播放 | 欧美国产日本一区 | 日韩精品一区二区三区中文字幕 | 欧美中文一区 | 国产精品激情 | 日本黄视频在线观看 | 日韩在线 | 天堂网中文字幕在线观看 | 久久人人网 | 日韩一区二区三区在线 | 欧美乱码精品一区二区三区 | 91青青草视频 | www.日日操| 91国在线高清视频 | 免费在线观看黄网站 | 自拍视频网站 | 日韩精品一区二区三区视频播放 | 91色视频在线观看 | 久久99精品久久久久久 | 黄色免费网站在线看 | 成人免费福利视频 | 欧美激情在线精品一区二区三区 | 精品视频一区在线 | 久久99视频| 妞干网福利视频 | 黄色在线免费观看 | 国产成人精品视频在线观看 | 日韩一区二区三区av | 色爽女| 欧美日韩精品一区 | 国产一区二区不卡 | 精品一二区 | 国产在线对白 |