答案 0 :(得分:1)
DECLARE @T TABLE
(CLIENTID INT,
STATUSID NVARCHAR(200),
STATUS NVARCHAR(200),
VALUE NVARCHAR(200),
CREATEDDATE DATETIME)
INSERT INTO @T
VALUES (25,100857,'SCHEME STATUS','CLIENT FOUND ELIGIBLE','2016-11-23 15:18:38:000'),
(25,100858,'REASON FOR DECLINING TO APPLY','TOO UNWELL','2016-11-23 15:18:38:000'),
(25,100858,'REASON FOR DECLINING TO APPLY','NOT INTRESTED','2016-11-23 15:18:38:000'),
(25,100858,'REASON FOR DECLINING TO APPLY','UNDECIDED','2016-11-23 15:18:38:000'),
(25,100859,'ELIGIBLE TO APPLY','YES','2016-11-23 15:18:38:000'),
(26,100857,'SCHEME STATUS','CLIENT NOT FOUND ELIGIBLE','2016-11-23 15:18:38:000'),
(26,100858,'REASON FOR DECLINING TO APPLY','TOO UNWELL','2016-11-23 15:18:38:000'),
(26,100858,'REASON FOR DECLINING TO APPLY','NOT INTRESTED','2016-11-23 15:18:38:000'),
(26,100858,'REASON FOR DECLINING TO APPLY','UNDECIDED','2016-11-23 15:18:38:000'),
(26,100859,'ELIGIBLE TO APPLY','YES','2016-11-23 15:18:38:000')
SELECT * FROM @T
WHERE CLIENTID IN (SELECT CLIENTID FROM @T WHERE STATUS = 'SCHEME STATUS' AND VALUE = 'CLIENT FOUND ELIGIBLE') OR
STATUSID NOT IN (SELECT STATUSID+1 FROM @T WHERE STATUS = 'SCHEME STATUS' AND VALUE = 'CLIENT NOT FOUND ELIGIBLE')