Hi ,
I'm trying to rewrite the below code which uses tmp tables developed in 2000 version of SQL to 2008 R2 .
any help in tuning query is appreciated..
-- Load all ip_id and skill combinations from tblSwDM_stg_SYNONYM into #temp_Complete_Skill_List INSERT #temp_Complete_Skill_List SELECT DISTINCT sm.switch_id, s.value, max(s.item_name), max(s.descr) FROM tblSwDM_stg_SYNONYM s (NOLOCK) INNER JOIN tblSwDM_SwitchMaster sm (NOLOCK) ON s.cms_id = sm.cms_id AND s.acd_no = sm.acd_number WHERE s.item_type = 'split' GROUP BY sm.switch_id, s.value -- Append all additional ip_id and skill combinations from tblSwDM_stg_DSPLIT_UNIQUE into #temp_Complete_Skill_List INSERT #temp_Complete_Skill_List SELECT DISTINCT stg.ip_id, stg.split, NULL, NULL FROM tblSwDM_stg_DSPLIT_UNIQUE stg (NOLOCK) LEFT OUTER JOIN #temp_Complete_Skill_List tmp ON stg.ip_id = tmp.switch_id AND stg.split = tmp.skill WHERE tmp.switch_id IS NULL AND tmp.skill IS NULL ---- The above code will be later used to load the table below.. UPDATE tblSwDM_Dictionary SET end_effective_date = @end_effective_date FROM tblSwDM_Dictionary INNER JOIN #temp_Updated_Skill ON tblSwDM_Dictionary.row_id = #temp_Updated_Skill.row_id WHERE tblSwDM_Dictionary.end_effective_date IS NULL INSERT INTO tblSwDM_Dictionary ([dictionary_type_id], [switch_id], [value], [name], [description], [start_effective_date]) SELECT DISTINCT dictionary_type_id, switch_id, skill, NULLIF(skill_name, ''), NULLIF(skill_description, ''), @start_effective_date FROM #temp_Updated_Skill
Thank you ,
vishal.