Search code examples
sqlstringsql-server-2005trim

Need specific string in SQL Server


I need your help guys.

I am trying to get specific word from the whole string in SQL Server.

I have following string:

'ABC, XYZ'

Need Output : ABC

Now I need only ABC out of whole string. I tried with Substring and Trim function but couldn't get appropriate output.

Could anyonel please help me?

Thank in advance!


Solution

  • Try to use patindex Example

    select SUBSTRING ('ABC, XYZ',1, PATINDEX ( '%,%', 'ABC, XYZ')-1)