Just check the alias names in your query. I don't see any alias called "T",but you are using that in your query here. As for the count, you could use something like this,SELECT ADR, T.UpperUser, T.ID, T.Amount,cnt.totFROM User ALEFT OUTER JOIN Name N ON A.UserNumber = N.UpperUserLEFT OUTER JOIN Totals S ON A.UserNumber = T.UpperUserLEFT JOIN (SELECT UpperUser,[ID],count(*) as tot FROM TotalsName GROUP BY UpperUser,[ID])cnt ON cnt.UpperUser=UpperUser and cnt.[ID]=[ID]WHERE A.DoneDate IS NULL AND N.Type IN (0,1) AND N.ADR='00001' AND T.Amount > 0 UNIONSELECT TN.ADR, TN.UpperUser, T.ID, T.Amount,cnt.totFROM User ALEFT OUTER JOIN Totals S ON A.UserNumber = T.UpperUserLEFT OUTER JOIN TotalsName SN ON T.UpperUser = TN.UpperUser AND T.ID = TN.UpperIDLEFT JOIN (SELECT UpperUser,[ID],count(*) as tot FROM TotalsName GROUP BY UpperUser,[ID])cnt ON cnt.UpperUser=UpperUser and cnt.[ID]=[ID]WHERE A.DoneDate IS NULL AND TN.Type = 1 AND ADR='00001' AND T.Amount > 0