Q&A for peer programmer code reviews
DECLARE @Person TABLE ( PersonID INT PRIMARY KEY ); INSERT INTO @Person (PersonID) VALUES (11),(22),(33),(44),(55),(66),(77),(88),(99)--,(100); --SELECT BusinessEntityID FROM Person.Person DECLARE @Department TABLE ( DepartmentID INT PRIMARY KEY ); INSERT INTO @Department(DepartmentID) VALUES (100), (200), (300); --SELECT DepartmentID FROM HumanResources.Department select EmployeeId, DepartmentId, RankEmployee, RankDepartment from ( select Rank() OVER(ORDER BY NEWID()) as RankEmployee , PersonID AS EmployeeId from @Person ) e , ( select Rank() OVER(ORDER BY NEWID()) as RankDepartment , (select count(1) from @Department) as CountDepartment , DepartmentID as DepartmentId from @Department ) d where (RankEmployee + RankDepartment) % CountDepartment = 0 --ORDER BY DepartmentId