insert into #tmp (CityID, CityName, TotalOrder)
Select distinct sr.RID as CityID,
sr.Rname as CityName
From #tmpID tid
Inner join StateRegions Sr on Sr.RID = tid.CityID
Group by Sr.RName,
sr.RID
Order by sr.RName
du forsøger at indsætte 3 kolonner i #tmp, men forespørgslen returnerer kun 2 kolonner
Jeg formoder, du vil have Count(*) eller Sum(ordrer) som tredje kolonne