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?
Microsoft SQL Server

Avatar of undefined
Last Comment
Scudboy
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Kevin Cross
Kevin Cross
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Scudboy
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
Scudboy

ASKER

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

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo