Assigning Skill From Excel Input Email-SkillName
DECLARE @tbl TABLE (
Id INT IDENTITY(1, 1)
,UserId INT
,CenterPguSkillId INT
)
INSERT INTO @tbl (
UserId
,CenterPguSkillId
)
SELECT
--s.[Level 1 Manager],
uEng.UserId
--,s.[Engineer Email]
--,uEng.UserName
--,uEng.SecondaryRole
--,s.[Delivery Type (Work Level)]
--,s.[Skill 1 to be Mapped]
,vsm.CenterPguSkillId
,CASE WHEN ucxps.Id IS NULL THEN 0 ELSE 1 END AS IsAssigned
FROM dbo.Sheet2$ s
LEFT JOIN dbo.[User] uEng ON s.[Engineer Email] = uEng.Email
LEFT JOIN dbo.vw_SkillMaster vsm ON s.[Skill 3 to be Mapped] = vsm.SkillName
LEFT JOIN dbo.UserXCenter ux ON uEng.UserId = ux.UserId
LEFT JOIN dbo.UserCenterXCenterPguSkill ucxps ON ux.UserXCenterId = ucxps.UserXCenterId AND ucxps.CenterXPGUXSkillId = vsm.CenterPguSkillId AND ucxps.IsActive = 1
WHERE s.[Skill 3 to be Mapped] is not null
DECLARE @i INT = 1
DECLARE @rowCount INT = 0
DECLARE @lpUserId INT = 0
DECLARE @lpCPSId INT = 0
DECLARE @loggedInUserId nvarchar(50) = ''
SELECT @rowCount = count(1)
FROM @tbl
WHILE (@i <= @rowCount)
BEGIN
SELECT @lpUserId = t.UserId
,@lpCPSId = t.CenterPguSkillId
FROM @tbl t
WHERE id = @i
EXEC [dbo].[USP_AssignEngineerToSKill] @centerId = 1
,@engUserId = @lpUserId
,@centerPguSkillId = @lpCPSId
,@loggedInUserId = @loggedInUserId
SET @i = @i + 1;
END