If I understand correctly, you want to modify this query to remove badge_num
from the aggregation. You cannot because of the correlated subquery. Try this:
SELECT t1.Badge_Num,
t2.UserDescription,
COUNT(p.Batch_Num) AS totallines
FROM Pack t1 WITH (NOLOCK) left outer join
JenX.dbo.Users t2
ON t1.Badge_Num = t2.UserName left outer join
Pick p
on p.Batch_Num = t1.Batch_Num
WHERE (t1.DateCreated BETWEEN '02/04/2014' AND '02/05/2014')
GROUP BY t2.UserDescription, t1.Badge_Num
ORDER BY t2.UserDescription, t1.Badge_Num;
The effect of the full outer join
is undone by the where
clause.