I inherited a list of stored procedures that are run in order that do some data error checking. The name of the procedures is stored in a table with a run order and the name is prefixed by a code denoting the severity of the error. (I know this should be in it's own column but it's not).
DECLARE @SPTypes as table (Client integer, Name varchar(100), RunOrder integer)
INSERT INTO @SPTypes
VALUES (100,'U - Update bad data',0),
(100,'X - Omit very bad data',1),
(100,'X - Omit for some other reasons',2),
(100,'W - Warn for some questionable data',3),
(100,'W - Warn for some other reasons',4),
(100,'OE - Overrideable Error some bad data',5),
(100,'OE - Overrideable Error for some other reasons',6),
(100,'E - Error some bad data',7),
(100,'E - Error for some other reasons',8),
(100,'U - Update records',9),
(200,'U - Update bad data',0),
(200,'X - Omit very bad data',1),
(200,'W - Warn for some questionable data',2),
(200,'W - Warn for some other reasons',3),
(200,'OE - Overrideable Error some bad data',4),
(200,'OE - Overrideable Error for some other reasons',5),
(200,'E - Error some bad data',6),
(200,'X - Omit for some other reasons',7),
(200,'E - Error for some other reasons',8),
(200,'U - Update records',9)
Step 1) I'd like to be able to group the prefixes of the procedures in their run order, I can get a list of ALL the prefixes in order, but I need to group them anytime there is a change in the prefix. (bad wording, see expected results below)
The query below gives all the prefixes in order, but I want to return a distinct grouping, by client, in the run order of the prefixes so every change in prefix writes a new row in the data.
SELECT LTRIM(RTRIM(SUBSTRING(Name,1,CHARINDEX('-',Name)-1))) from @SPTypes
ORDER BY RunOrder
*Expected Results for Client 100
U
X
W
OE
E
U
Client 200 would look like
U
X
W
OE
E
X
E
U
Step 2) I think I can do this once I get Step 1 done, but I want to compare the results against a list to make sure that there aren't any X's below any E's. The order for client 100 above is correct, but there are some instances where the order is bad and I want to try and track them down. A valid pattern would is U,X,W,OE,E,U, so client 200 is bad.