if OBJECT_ID(N'tempdb..#tempTable',N'U') Is Not NUll Drop Table #tempTable select id into #tempTable from TB