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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need to extract text before a dash

Author  Topic 

GaryNull
Starting Member

14 Posts

Posted - 2012-12-11 : 21:23:38
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 - 2012-12-11 : 21:30:25
select left(yourfield, charindex('-',yourfield)-1)
from yourtable
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-12-11 : 21:31:20
[code]Select Substring(columnname,1,Charindex('-',columnname)-2) from Table[/code]
Go to Top of Page

GaryNull
Starting Member

14 Posts

Posted - 2012-12-11 : 22:02:21
thanks guys, both worked perfectly
Go to Top of Page
   

- Advertisement -