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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need to extract text before a dash
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

GaryNull
Starting Member

USA
12 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

151 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
12 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  
 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.05 seconds. Powered By: Snitz Forums 2000