0

I have a column of values that are as shown below:

ID
x-644478134
x-439220334
x-645948923
x-10686843432
x-4273883234

I would like to return a column like so:

ID
644478134
439220334
645948923
10686843432
4273883234

Can someone advise how to do this cleanly? I believe it is something to do with substring but not sure exactly

SELECT SUBSTRING(d.ID)
FROM data d
Blackdynomite
  • 421
  • 1
  • 4
  • 18

1 Answers1

1

You need to use substring, charindex and len functions such as below, assuming the dash (-) is the separator of the text and numeric part:

declare @x varchar(50) = 'a-0123'
select substring(@x,CHARINDEX('-',@x,1)+1,len(@x)-CHARINDEX('-',@x,1))

If you are sure that ID always starts with x-, then:

Select substring(ID,3,LEN(ID)-2) 
Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82