Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select clause with citeria

Author  Topic 

Johnph
Posting Yak Master

103 Posts

Posted - 2013-09-12 : 16:08:22
I have data that looks like this:

CAT_2
DOG_22
MICE_1321
MONKEY_2123
TIGER_1

I need the select statement to select everything before the "_"


CAT
DOG
MICE
MONKEY
TIGER

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-09-12 : 16:09:57
[code]
SELECT LEFT(columnname,CHARINDEX('_',ColumnName + '_')-1) AS RequiredValue FROM Table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -