how to select next n letters after one specific letter using function in sql server by giving function name,specific letter, no of letters next

Mixture of CHARINDEX with SUBSTRING if on SQL Server.

DECLARE @Text VARCHAR(100) = 'The cat is under the table.'

DECLARE @CharToSearch CHAR = 's'
DECLARE @CharactersToRetrieve INT = 5

    CharacterPosition = CHARINDEX(@CharToSearch, @Text),
    TrimmedString = SUBSTRING(
        CHARINDEX(@CharToSearch, @Text) + 1,


CharacterPosition   TrimmedString
10                   unde

Browse More Popular Posts

Leave a Comment