IF @IsAssigning = 1
BEGIN
INSERT INTO [dbo].[ProductMapping] ([ProductId], [OrganizationId], [ProductSeriesId], [CenterXPGUXSkillId], [IsActive], [CreatedBy], [CreatedDate])
SELECT tbl.ProductId, @OrganizationId, tbl.ProductSeriesId, @SkillId, 1, @UserId, GETDATE()
FROM @tblProducts tbl
WHERE tbl.ProductId NOT IN (
SELECT PM.ProductId
FROM ProductMapping PM WITH (NOLOCK)
WHERE PM.IsActive = 1
AND pm.OrganizationId = @OrganizationId
AND pm.CenterXPGUXSkillId = @SkillId
)
END
or --Best
INSERT INTO dbo.TCIAssessmentResultSummary (AssessmentMode, UserId, ActivityId, Rating, AppearedDate, Isactive)
SELECT 'NA', tbl.UserId, tbl.ActivityId, tbl.Rating, GETDATE(), 1
FROM #TEMP tbl
WHERE NOT EXISTS (
SELECT 1
FROM TCIAssessmentResultSummary A
WHERE A.UserId = tbl.UserId
AND A.ActivityId = tbl.ActivityId
AND Isactive = 1
)