SQL Select statement left of first dash

How do I do a select statement to get everything to left of first dash?

Select   on this

col1  
S18-8162694936
WebSM-2345879542

Shoudl return
colNew
S18
WebSM
Larry Bristersr. DeveloperAsked:
Who is Participating?
 
LowfatspreadConnect With a Mentor Commented:
select left(col1,case when col1 like '%-%' then charindex('-',col1)-1 else len(col1) end) as newcol
0
 
Partha MandayamTechnical DirectorCommented:
What if there's no dash in the data? How are you getting colNew
0
 
Larry Bristersr. DeveloperAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.