How to get text between two words/characters

前端 未结 4 762
不知归路
不知归路 2021-01-27 01:15

How can I get some text between two known words?

Sub-select example:

(SELECT TOP(1)Note
FROM Clients
WHERE (ID=@ID) AND (Note IS NOT NULL) AND (Note NOT         


        
4条回答
  •  囚心锁ツ
    2021-01-27 01:46

    declare @start varchar(100)
    set @start = 'startword'
    
    declare @end varchar(100)
    set @end = 'endword'
    
    SELECT TOP(1) Note , substring( LEFT(note, charindex(@end, note, CHARINDEX(@start, note))-1), CHARINDEX(@start, note) + len(@start), LEN(note))   result
    FROM Clients
    WHERE (ID=@ID) AND (Note IS NOT NULL) 
    

提交回复
热议问题