Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem when using count
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Divers
Thread ID:
00392388
Message ID:
00392433
Vues:
9
>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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform