Link to home
Start Free TrialLog in
Avatar of Scudboy
Scudboy

asked on

Transact SQL challenge - Trim data after a special character

I am trying to return a string up to a certain character, and cannot figure out what I should be using.  This may be a newbie question...
Basically, a varchar(255) column named COMMENT has the following value:
  'Working on a solution to get this to appear_NOT THIS'

When I select that column I would like the result to be
  'Working on a solution to get this to appear'

So effectively trimming everything to the right of the _ (underscore).

Is that even possible?
Avatar of Scudboy
Scudboy

ASKER

I should clarify, the values held in this column will not be have a consistant number of leading characters - so the values would/could be:

COMMENTCOLUMN
I would like this to appear_NOT THIS
Working on a solution to get this to appear_NOT THIS
This is what we'd want to show up_NOT THIS SECTION
This is good_this is bad and we do not want it to show up in the return list of values.
SOLUTION
Avatar of dba2dba
dba2dba

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
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America 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
Avatar of Scudboy

ASKER

Hi dba2dba -
The issue with using the statement above is that it assumes the removed text will be consistent.  This won't be the case.

In this example -
COMMENTCOLUMN
I would like this to appear_NOT THIS
Working on a solution to get this to appear_NOT THIS
This is what we'd want to show up_NOT THIS SECTION
This is good_this is bad and we do not want it to show up in the return list of value

Open in new window


We'd want to remove everything after the underscore (or # sign, or whatever would work in this capacity).
Avatar of Scudboy

ASKER

MWVisa1 nailed it - thanks much for the assistance, split points per request!