Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem when using count
Message
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00392388
Message ID:
00392433
Views:
8
>I tried this SQL in a VB app and I get an expected 1 error. Where is the error in this SQL. (What I want to do is only return employees if they have reportrequests.)
>
>SELECT Employees.ID, Employees.FirstName,
> Employees.LastName, Employees.Department,
> COUNT(ReportRequests.ID) AS Ctr
>FROM Employees, ReportRequests
>WHERE Employees.ID = ReportRequests.EmpID AND (Ctr > 0)
>GROUP BY Employees.ID, Employees.FirstName,
> Employees.LastName, Employees.Department

Change the Ctr part of the WHERE clause to a HAVING clause using the actual COUNT() statement:

SELECT Employees.ID, Employees.FirstName,
Employees.LastName, Employees.Department,
COUNT(ReportRequests.ID) AS Ctr
FROM Employees, ReportRequests
WHERE Employees.ID = ReportRequests.EmpID
HAVING Count(ReportRequests.ID) > 0
GROUP BY Employees.ID, Employees.FirstName,
Employees.LastName, Employees.Department
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform