[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 557
  • Last Modified:

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
0
lrbrister
Asked:
lrbrister
1 Solution
 
LowfatspreadCommented:
select left(col1,case when col1 like '%-%' then charindex('-',col1)-1 else len(col1) end) as newcol
0
 
mcp111Commented:
What if there's no dash in the data? How are you getting colNew
0
 
lrbristerAuthor Commented:
Thanks
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now