HiCan anyone tell me a better way of doing the following: I have a list of employers and for each I want to assign 3 roles. see code below. Basically i don't want to repeat the same code for each of the roles I am inserting,DECLARE @CurrentRow intDECLARE @RowCount int, @RoleId int, @EmployerId int, @AuthId int, @RoleName varchar(50)-- Insert all employers into temp tableDECLARE @temptable table(Id int primary key identity(1,1), EmployerId int)-- get all employersINSERT INTO @temptable (EmployerId)SELECT DISTINCT EmployerIdFROM t_Org WHERE NOT EmployerId IS NULLSELECT @CurrentRow = 1SELECT @RowCount=COUNT(Id) FROM @temptableBEGIN --For each record in @temptable give role to employer for user WHILE @CurrentRow <= @RowCount BEGIN SET @RoleName = 'Reference Table Manager' SELECT @RoleId = Id FROM t_RolesforUser WHERE [Name] = @RoleName SELECT @EmployerId = EmployerId FROM @temptable WHERE Id = @CurrentRow INSERT INTO UsersRole( UId, RId, EmpId) SELECT @AuthId, @RoleId, @EmployerId SELECT @CurrentRow = @CurrentRow + 1 END --For each record in @temptable give role to employer for user with role WHILE @CurrentRow <= @RowCount BEGIN SET @RoleName = 'Departmental Transfers' SELECT @RoleId = Id FROM t_RolesforUser WHERE [Name] = @RoleName SELECT @EmployerId = EmployerId FROM @temptable WHERE Id = @CurrentRow INSERT INTO UsersRole( UId, RId, EmpId) SELECT @AuthId, @RoleId, @EmployerId SELECT @CurrentRow = @CurrentRow + 1 END --For each record in @temptable give role to employer for user WHILE @CurrentRow <= @RowCount BEGIN SET @RoleName = 'National File Manager' SELECT @RoleId = Id FROM t_RolesforUser WHERE [Name] = @RoleName SELECT @EmployerId = EmployerId FROM @temptable WHERE Id = @CurrentRow INSERT INTO UsersRole( UId, RId, EmpId) SELECT @AuthId, @RoleId, @EmployerId SELECT @CurrentRow = @CurrentRow + 1 ENDEND