Question : SQL Query

I'm using VB.net program to query SQL Server 2005.

This query works fine, except it is incomplete. I also need field PAacct in the Emp$ table which contains text. I want to add it to my select statement, but I do NOT want to group by this field. I can't sum or count it since I want the text.

I can't seem to make this work without adding it to the Group By area. I really only want to Group By C.Comp_ID.  The other groupings are there because the query doesn't work without them but if I could remove them, I would. The new field E.PAacct comes from the $emp table, so grouping would be a problem.

How can I get this field without grouping by it?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
SELECT  C.Type, C.Comp_ID, C.Year, C.Comp_Name, C.Phone, 	COUNT(E.CompID) AS EmpCount, SUM(E.Wages) AS Wages, SUM(E.FedTax) AS FedTax

FROM     Com$ AS C INNER JOIN 
               Emp$ AS E ON C.Comp_ID = E.CompID AND C.Year = E.Year

WHERE  (C.Year = @YearParam)

GROUP BY C.Comp_ID, C.Type, C.Year, C.Comp_Name, C.Phone

ORDER BY C.Comp_ID

Answer : SQL Query

SELECT  C.Type, C.Comp_ID, C.Year, C.Comp_Name, C.Phone,       COUNT(E.CompID) AS EmpCount, SUM(E.Wages) AS Wages, SUM(E.FedTax) AS FedTax, (SELECT TOP 1 PAacct  FROM Emp$ p where C.Comp_ID = p.CompID AND C.Year = p.Year ) as PAccnt
FROM     Com$ AS C INNER JOIN
               Emp$ AS E ON C.Comp_ID = E.CompID AND C.Year = E.Year

WHERE  (C.Year = @YearParam)
GROUP BY C.Comp_ID, C.Type, C.Year, C.Comp_Name, C.Phone

ORDER BY C.Comp_ID
Random Solutions  
 
programming4us programming4us