I have a column called external ref
in the table transaction
using one row as example
ITS trans code: 1188716 ITS batch: 78606 15/16
- 1188716 is the trans number
- 78606 is the batch id
- 15/16 is the date
I am only interested in the trans and batch id
I originally did
SELECT
SUBSTRING(ts.ext_ref, 17, 7) AS transaction_id,
SUBSTRING(ts.ext_ref, 34, 7) batch_id
FROM transactions ts
it stopped working because both 1188716 and 78606 are not fixed length I could get transaction id 123 batch id 456 or transaction id 12345566 batch id 45678990
I want to achieve the logic such as paring any continuous number of digits between the 3rd and 4th spaces and the same logic on the 6th and 7th spaces
is it possible to achieve this in SQL server?