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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need to extract text before a dash
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

GaryNull
Starting Member

USA
14 Posts

Posted - 12/11/2012 :  21:23:38  Show Profile  Reply with Quote
Hi,
I need to extract all the text before the first dash.
For example the fields :

COBRA DIGITAL - DPS-2300 WAND
becomes
COBRA DIGITAL

and

ROYAL - 29421N
becomes
ROYAL

Can anyone help? thanks

singularity
Posting Yak Master

153 Posts

Posted - 12/11/2012 :  21:30:25  Show Profile  Reply with Quote
select left(yourfield, charindex('-',yourfield)-1)
from yourtable
Go to Top of Page

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 12/11/2012 :  21:31:20  Show Profile  Reply with Quote
Select Substring(columnname,1,Charindex('-',columnname)-2) from Table
Go to Top of Page

GaryNull
Starting Member

USA
14 Posts

Posted - 12/11/2012 :  22:02:21  Show Profile  Reply with Quote
thanks guys, both worked perfectly
Go to Top of Page
  Previous Topic Topic Next 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