--SELECT * FROM dbo.UserCenterXCenterPguSkill ucxps
--UPDATE dbo.UserCenterXCenterPguSkill
--SET
-- dbo.UserCenterXCenterPguSkill.LatestAssessmentId = NULL,
-- dbo.UserCenterXCenterPguSkill.Rating = null
BEGIN
DECLARE @assessmentId INT = 0
DECLARE @rating INT = 0
DECLARE @tbl TABLE (
Id INT IDENTITY(1, 1)
,uccpsId VARCHAR(100)
)
DECLARE @uccpsId INT
DECLARE @I INT = 1
,@I_RowCount INT
INSERT INTO @tbl (uccpsId)
SELECT ucxps.Id
FROM dbo.UserCenterXCenterPguSkill ucxps
SET @I_RowCount = @@ROWCOUNT
SET @I = 1
WHILE (@I <= @I_RowCount)
BEGIN
SELECT @uccpsId = uccpsId
FROM @tbl
WHERE Id = @I
SET @assessmentId = NULL
SET @rating = NULL
SELECT TOP 1 @assessmentId = a.AssessmentId
,@rating = tr.Rating
FROM dbo.Assessment a
INNER JOIN dbo.TCIAssessmentResult tr ON a.AssessmentId = tr.AssessmentId
AND tr.Isactive = 1
WHERE a.UserCenterXCenterPguSkillId = @uccpsId
ORDER BY a.CompletedDate DESC
IF (@assessmentId IS NOT NULL)
BEGIN
UPDATE dbo.UserCenterXCenterPguSkill
SET dbo.UserCenterXCenterPguSkill.LatestAssessmentId = @assessmentId
,dbo.UserCenterXCenterPguSkill.Rating = @rating
WHERE dbo.UserCenterXCenterPguSkill.Id = @uccpsId
END
SET @I = @I + 1
--
END
END
--