Not quite...this is what I meant, so we wouldn't have to write it ...DECLARE @MITagging Table ( ReqID int not null, CustomerName char(6) not null, MITaggingStatus varchar(9) not null, AssignedTo varchar(5) null)INSERT INTO @MITaggingSELECT 1 ,'Cust 1', 'Done', NULL UNIONSELECT 2 ,'Cust 2', 'Pending', NULL UNIONSELECT 3 ,'Cust 3', 'Pending', NULL UNIONSELECT 4 ,'Cust 4', 'Done', NULL UNION SELECT 5 ,'Cust 5', 'Pending', NULLDECLARE @UserRights Table ( UserID varchar(5) not null, CurrentStatus varchar(8) not null)INSERT INTO @UserRightsSELECT 'User1', 'Active' UNIONSELECT 'User2', 'Active' UNIONSELECT 'User3', 'InActive'SELECT UserID, UserRow = ROW_NUMBER() OVER( PARTITION BY CurrentStatus ORDER BY CurrentStatus) FROM @UserRights Where CurrentStatus = 'Active'SELECT REQID, ReqRow = ROW_NUMBER() OVER (PARTITION BY MITaggingStatus ORDER BY MITaggingstatus) FROM @MITagging Where MITaggingStatus = 'Pending'------------------------------------------;WITH cteActiveUsers AS ( SELECT UserID, UserRow = ROW_NUMBER() OVER( PARTITION BY CurrentStatus ORDER BY CurrentStatus) FROM @UserRights Where CurrentStatus = 'Active' ) , ctePending AS ( SELECT REQID, ReqRow = ROW_NUMBER() OVER (PARTITION BY MITaggingStatus ORDER BY MITaggingstatus) FROM @MITagging Where MITaggingStatus = 'Pending' )UPDATE tSET AssignedTo = cteActiveUsers.UserID ,MITaggingStatus = 'Done'FROM cteActiveUsers join ctePending on UserRow = ReqRow join @MITagging t on t.ReqID = ctePending.REQIDWHERE MITaggingStatus = 'Pending'SELECT * FROM @MITagging
What would the desired results be from that ? I am not sure what results you want, but I think the results of the above match....correct?
Poor planning on your part does not constitute an emergency on my part.