iT邦幫忙

0

MS SQL Server 搜尋欄位含有dash或hyphen (-)字串

KL 2022-01-03 11:49:45911 瀏覽
  • 分享至 

  • xImage

建置sql server table時遇到搜尋的欄位含有dash或hyphen (-)字串時,無法返回正確的搜尋結果,必須使用'like'替代'='完整字串搜尋才能返回正確結果。

同樣的搜尋卻有些table可以使用'='完整字串搜尋含有dash或hyphen (-)字串並返回正確結果。

我的欄位字串格式為

ABCDEF-010203

在確認table的design後發現,在Full-text Specification中Language的設定有差異,可以搜尋dash/hyphen的為空白,不可搜尋dash/hyphen的為Neutral只能使用like搜尋。我猜測可能是這個Language設定可以調整搜尋遇到dash/hyphen的結果。想請問怎麼把dash/hyphen改為空白?謝謝

https://ithelp.ithome.com.tw/upload/images/20220103/20139417Bi0AFJmbSD.png

以下是幾篇微軟官方網站關於這個問題的描述:
https://docs.microsoft.com/en-US/troubleshoot/sql/admin/dashes-ignored-search-full-text-msidxs-queries

https://docs.microsoft.com/en-us/sql/relational-databases/search/choose-a-language-when-creating-a-full-text-index?view=sql-server-ver15

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
Samuel
iT邦好手 1 級 ‧ 2022-01-03 13:46:10

可以嘗試看看用charindex
做Contains比對
CHARINDEX('特定目標子字串','完整字串欄位') >= 1
https://coolmandiary.blogspot.com/2021/06/t-sql17startwithcontainscharindex.html

REPLACE這個可以用來做字元取代
https://coolmandiary.blogspot.com/2021/03/t-sql13trim-solutionreplacertrimltrim.html

或者檢查一下定序
https://coolmandiary.blogspot.com/2021/12/t-sql27where.html

我要發表回答

立即登入回答