0

If I pull this ID down from my source system it looks like 9006ABCD.

What would the syntax look like if I just want to return 9006 as the ID?

Essentially, I don't need the alpha characters.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

3

Assuming that '9006ABCD' is a string value, then you can extract the leading numbers using:

select left(id, patindex('%[^0-9]%', id + 'X') - 1)

Of course, there may be easier ways. If you just want the first four characters, then use left(id, 4).

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786