Check your data:
SELECT [Status]
FROM CustomPollerStatus
WHERE [Status] LIKE '%T%'
Your @flaglist variable is varchar but you compare it (or rather, a substring of it) to a numeric:
WHEN SUBSTRING(@flaglist,@flagpos,1)=1 and @counter = 31 THEN 'Graceful Shutdown Issued by Upstream Device, '
You could change that to a varchar too:
WHEN SUBSTRING(@flaglist,@flagpos,1) = '1' and @counter = 31 THEN 'Graceful Shutdown Issued by Upstream Device, '
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden