bandi
Master Smack Fu Yak Hacker
2242 Posts |
Posted - 2013-02-21 : 02:42:09
|
[code]DECLARE @tab TABLE(WorkRequest VARCHAR(10), WorkSegment VARCHAR(20), ChildSegment int, Status VARCHAR(10), Equipment VARCHAR(15))INSERT INTO @tabSELECT 'IAM2001', 'FK19929100101', 311, 'Complete', '001VALID' union allSELECT 'IAM2001', 'FK19929120501', 111, 'Pending', '005VERBO' union allSELECT 'IAM2001', 'FK19929120501', 121, 'Pending', '005VERBO' union allSELECT 'IAM2001', 'FK19929141001', 111, 'Pending', '010CONTU' union allSELECT 'IAM2001', 'FK19929141001', 121, 'Pending', '010CONTU' union allSELECT 'IAM2002', 'FK19929100101', 311, 'Complete', '001VALID' union allSELECT 'IAM2002', 'FK19929120501', 111, 'Complete', '005VERBO' union allSELECT 'IAM2002', 'FK19929120501', 121, 'Complete', '005VERBO' union allSELECT 'IAM2002', 'FK19929141001', 111, 'Pending', '010CONTU' union allSELECT 'IAM2002', 'FK19929141001', 121, 'Pending', '010CONTU'--I need to get the below two recordsSELECT WorkRequest, WorkSegment, ChildSegment, Status, EquipmentFROM (SELECT *, ROW_NUMBER() OVER( PARTITION BY WorkRequest ORDER BY (select 1)) RN FROM @tab WHERE Status = 'pending' ) tWHERE RN=1[/code]--Chandu |
|
|