CREATE TABLE test
(
[message] NVARCHAR(100) NULL,
)
INSERT INTO test
values
('Location set to: Loc1, Order: 1, item: shirt-red.large, company: 01, store: 01'),
('Location set to: Loc1, Order: 1, item: shirt-red.medium, company: 01, store: 01'),
('Location set to: Loc2, Order: 220, item: shirt-blue.small, company: 01, store: 089'),
('Location set to: Loc2, Order: 220, item: shirt-blue.medium, company: 01, store: 089')
In SQL Server (2016), I'm trying to extract the full item string from the above column (e.g. 'shirt-red.large', 'shirt-blue.small' etc), using CHARINDEX to search for 'Item: ' and ', ', but I'm getting following error
"Invalid length parameter passed to the LEFT or SUBSTRING function"
Is this something to do with the ', ' being present multiple times in the string? What would be the best way to isolate the item as a result?