I have this:
21654-8012
1234-127834
12345-1222
I want to extract this:
21654
1234
12345
Basically, everything before the hyphen, -
character. Does anyone have any suggestions on where to start?
I have this:
21654-8012
1234-127834
12345-1222
I want to extract this:
21654
1234
12345
Basically, everything before the hyphen, -
character. Does anyone have any suggestions on where to start?
Use left
WITH charindex()
:
select t.col, left(col, charindex('-', col)-1)
from table t;
You can use CHARINDEX function
DECLARE @text VARCHAR(20)
SET @text = '123456-0000'
SELECT SUBSTRING(@text, 0, CHARINDEX('-', @text))
Instead of @text, you can use your field name
SELECT SUBSTRING(YOUR_COLUMN_NAME, 0, CHARINDEX('-', YOUR_COLUMN_NAME)) FROM YOUR_TABLE_NAME