I am having a problem getting the results that I want to get from my SQL statement. I know that I probably missed something simple, but I just don't see it.
Here are my tables.
Table: Users (RoleID is linked to ID in Roles Table)
ID , FirstName , LastName , RoleID
1, Matt, Ryan, 1
2, Chipper, Jones, 1
3, Julio, Jones, 2
4, Jason, Bourn, 3
Table: Roles
ID , Name
1, Field Rep
2, Tech
3, admin
Table: FRrequests (UserID is linked to ID in Users table)
ID , UserID , Status
1, 1, Open
2, 1, Submitted
3, 1, Delayed
4, 1, Complete
What I want is an SQL statement that shows me the number of all Sent and Pending requests for all fields. The following is an example of the desired results.
Name count
Chipper Jones 0
Matt Ryan 2
Here is the expression that I still have, and the results that he gives me.
SELECT Users.FirstName + '' + Users.LastName AS Name, COUNT (FRrequests.ID) AS 'Open Requests' FROM Users INNER JOIN Roles ON Users.RoleID = Roles.ID LEFT OUTER JOIN FRrequests ON Users.ID = FRrequests.UserID WHERE (Roles.Name = N'Field Rep ') AND (FRrequests.Status =' Submitted 'OR FRrequests.Status =' Delayed ') GROUP BY Users.FirstName, Users.LastName Name Count Matt Ryan 2
I know that the AND part (FRrequests.Status = 'Submitted "or FRrequests.Status =' Delayed ') is what violates it. If I run it without this in the application, I will get all the users, but it will calculate that the whole status is not just sent and delayed. I just can't figure out what I'm missing to get this to work. Any help would be greatly appreciated.