Trim in T-sql

Hi

I have a column which has    'Ram, Rishi, Tapas'.

I want to display only Ram.  How to trim after ram .
Ravee123Asked:
Who is Participating?
 
Lee SavidgeCommented:
left(mycolumn, charindex(',', mycolumn) - 1)
0
 
LIONKINGCommented:
If it's always at the beginning you could do a left, like:

SELECT LEFT(myColumn,3)

If it can be anywhere, something like this can help:

SELECT SUBSTRING(yourColumnName,CHARINDEX('Ram',yourColumnName),3)

If there are values that don't contain your text, you're going to have to handle them with a case statement.

Hope it helps.
0
 
Ravee123Author Commented:
Hi

That column has several data.

Ram, Rishi, Tapas
Stephen,Greek,John
Pathan, Doni, Sachin.


I want to display only the first value like

Ram
Stephen
Pathan
0
 
LIONKINGCommented:
That's a bit different from the OP, but this should help:

SUBSTRING(yourColumnName,1,CHARINDEX(',',yourColumnName)-1)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.