Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Count and Group by

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2005-10-27 : 03:06:18
i tried to do in my select a count function
like this :

SELECT WCD.debt_id, Comp.Name, WCD.client_id, WCD.client_name, WCD.AdminID, FA.FirstName + ' ' + FA.LastName AS AdminName, CONVERT(NVARCHAR(10), WCD.CreateDate, 103) AS CreateDate, COUNT(WCS.status_id) AS countStatus
FROM WCD
LEFT OUTER JOIN Comp ON WCD.CompanyID = Comp.CompanyID
LEFT OUTER JOIN FA ON WCD.AdminID = FA.AdminId
LEFT OUTER JOIN WCS ON WCD.debt_id = WCS.debt_id
GROUP BY
WCD.debt_id, Comp.Name, FA.FirstName + ' ' + FA.LastName, WCD.client_id, WCD.client_name, WCD.AdminID, WCD.CreateDate, WCS.status_id
ORDER BY WCD.CreateDate DESC

the thing is that until i didnt add all the group by fields i got error messages!!!
i thhought that its enough only to do :

GROUP BY
WCD.debt_id

why isnt this enought?thnaks i nadvance
peleg

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2005-10-27 : 03:45:12
quote:


From BOL
The GROUP BY keywords are followed by a list of columns, known as the grouping columns. The GROUP BY clause restricts the rows of the result set; there is only one row for each distinct value in the grouping column or columns. Each result set row contains summary data related to the specific value in its grouping columns.

There are restrictions on the items that can be specified in the select list when a SELECT statement contains a GROUP BY. Items allowed in the select list are:

The grouping columns.


Expressions that return only one value for each value in the grouping columns, such as aggregate functions that have a column name as one of their parameters. These are known as vector aggregates.





--------------------
keeping it simple...
Go to Top of Page
   

- Advertisement -