The INTO part creates the table for you.DROP TABLE tmp_claimeligiblebalanceGOSELECT clpid, Sum(cloutstandingamt) as sumoutstandingINTO tmp_ClaimEligibleBalanceFROM tsd_ClaimGROUP BY clpidHAVING sum(cloutstandingamt) <> 0 And max(clfromdos) < DATEADD(DAY, -120, getdate()) And max(clins) IS NOT NULL
If you are going to reuse the table, why not just TRUNCATING the table?TRUNCATE TABLE tmp_claimeligiblebalanceINSERT tmp_claimeligiblebalance ( clpid, sumoutstanding )SELECT clpid, Sum(cloutstandingamt)INTO tmp_ClaimEligibleBalanceFROM tsd_ClaimGROUP BY clpidHAVING sum(cloutstandingamt) <> 0 And max(clfromdos) < DATEADD(DAY, -120, getdate()) And max(clins) IS NOT NULL
E 12°55'05.25"N 56°04'39.16"