?
Solved

Trim in T-sql

Posted on 2012-09-05
4
Medium Priority
?
387 Views
Last Modified: 2012-09-17
Hi

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

I want to display only Ram.  How to trim after ram .
0
Comment
Question by:Ravee123
  • 2
4 Comments
 
LVL 13

Expert Comment

by:LIONKING
ID: 38368350
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
 

Author Comment

by:Ravee123
ID: 38368372
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
 
LVL 13

Expert Comment

by:LIONKING
ID: 38368391
That's a bit different from the OP, but this should help:

SUBSTRING(yourColumnName,1,CHARINDEX(',',yourColumnName)-1)
0
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 1000 total points
ID: 38368445
left(mycolumn, charindex(',', mycolumn) - 1)
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Loops Section Overview

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question