SUBSTRING Functions

Hello Everyone and good evening.

Could anyone help with this.

DECLARE @ListSplitName TABLE(Name VARCHAR(255))

INSERT INTO @ListSplitName
VALUES
('Inv 3225366, BUK-100694, London Distribution Solutions B, PICKING 37,531 @£0.20')

SELECT * FROM @ListSplitName;

I have tried using this function - substring(name , charindex(',',name)+2,LEN(name)) from FROM @ListSplitName but, is not doing the job

I only want BUK-00694 from the string.

Any help would be apprciated.

Thanks

You need to use 2 `CHARINDEX()`

SELECT SUBSTRING(name, c1 + 1, c2 - c1 - 1)
FROM   @ListSplitName n
       CROSS APPLY
       (
           SELECT c1 = CHARINDEX(',', name)
       ) c1
       CROSS APPLY
       (
           SELECT c2 = CHARINDEX(',', name, c1 + 1)
       ) c2