SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select clause with citeria
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Johnph
Yak Posting Veteran

95 Posts

Posted - 09/12/2013 :  16:08:22  Show Profile  Reply with Quote
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

India
52309 Posts

Posted - 09/12/2013 :  16:09:57  Show Profile  Reply with Quote

SELECT LEFT(columnname,CHARINDEX('_',ColumnName + '_')-1) AS RequiredValue FROM Table 


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000