Reputation: 51
I am trying to run a query where
,replace(b.[X.Logs],' ','.') as 'logs'
,CT2 as
(
Select *
, CHARINDEX('Diagnostics',[logs]) as 'DiagBGN1'
, CHARINDEX('.',[logs],CHARINDEX('Diagnostics',[logs])) as 'DiagEND1'
From CT1
)
,CT3 as
(
Select *
,SUBSTRING([logs],[EPSABGN1]+1,[EPSAEND1]-[EPSABGN1]-1) as 'EPSA_CODE'
From CT2
)
I would like the Code to Skip the first .
and select the next preceding .
as the delimiter.
Upvotes: 0
Views: 1442
Reputation: 6524
You can use it like below:
declare @S varchar(200) = 'Diagnostics.Passed.hardware';
select substring(@s, charindex('.', @S)+1, len(@s));
CharIndex will provide the 'index' of the first '.' and then use it to get substring from the string. This will 'ignore' the word "Diagnostics." from the string.
Upvotes: 1