troubleshooting Question

Microsoft SQL SUBSTRING variable length LEN string extraction

Avatar of Scott Abraham
Scott AbrahamFlag for United States of America asked on
MicrosoftSQL
4 Comments1 Solution4 ViewsLast Modified:
I am on the struggle bus extracting the sequence number from the following data example:

DEVICE,DESCRIPTION
Meter,Meter event Primary Power Down Time event occurred on meter = 11/29/2019 16:30:55 Sequence number = 6201 User id = 0 Event argument = 00-00
Meter,Meter event Primary Power Down Time event occurred on meter = 11/29/2019 21:18:37 Sequence number = 10233 User id = 0 Event argument = 00-00
Meter,Meter event Primary Power Down Time event occurred on meter = 11/29/2019 15:17:16 Sequence number = 510 User id = 0 Event argument = 00-00
MeteR,Meter event Primary Power Down Time event occurred on meter = 11/29/2019 15:17:23 Sequence number = 513 User id = 0 Event argument = 00-00

I basics of what I have are:
SELECT DEVICE
      ,DESCRIPTION
      ,SUBSTRING(DESCRIPTION
               ,101
               , 4
            ) AS 'SEQUENCE'

FROM EVENTS

That of course cuts off values above 9999 for sequence.  I cannot figure out how to have the length stop at the space after the sequence number.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros