Link to home
Start Free TrialLog in
Avatar of Ravee123
Ravee123

asked on

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 .
Avatar of Member_2_861731
Member_2_861731
Flag of Canada image

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.
Avatar of Ravee123
Ravee123

ASKER

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
That's a bit different from the OP, but this should help:

SUBSTRING(yourColumnName,1,CHARINDEX(',',yourColumnName)-1)
ASKER CERTIFIED SOLUTION
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial