jancooth
jancooth

Reputation: 567

SQL Server - how can I get a string that starts with specific characters

I want to get a string starts with @ from full text.

My text is:

" Hello this is @jancooth from paradise"

I only want to get the @jancooth part.

Upvotes: 0

Views: 670

Answers (1)

WAMLeslie
WAMLeslie

Reputation: 1261

CHARINDEX with SUBSTRINGs will work for you, assuming there is only one instance of @.

declare @testtext NVARCHAR(50) = 'Hello this is @jancooth from paradise'

select substring(@testtext,charindex('@',@testtext), charindex(' ',@testtext,charindex('@',@testtext)) - charindex('@',@testtext))

Upvotes: 1

Related Questions