sql searching multiple words in a string

前端 未结 8 731
故里飘歌
故里飘歌 2020-12-09 02:35

What is the most efficient and elegant SQL query looking for a string containing the words \"David\", \"Moses\" and \"Robi\". Assume the table is named T an

8条回答
  •  -上瘾入骨i
    2020-12-09 03:11

    Here is what I uses to search for multiple words in multiple columns - SQL server

    Hope my answer help someone :) Thanks

    declare @searchTrm varchar(MAX)='one two three ffffd 20   30 comment'; 
    --select value from STRING_SPLIT(@searchTrm, ' ') where trim(value)<>''
    select * from Bols 
    WHERE EXISTS (SELECT value  
        FROM STRING_SPLIT(@searchTrm, ' ')  
        WHERE 
            trim(value)<>''
            and(    
            BolNumber like '%'+ value+'%'
            or UserComment like '%'+ value+'%'
            or RequesterId like '%'+ value+'%' )
            )
    

提交回复
热议问题