Hi All,
I have Sub-Query SQL question.
I can’t figure out the correct Sub-Query SQL that will count the amount of ServiceDate records per day.
I want the CountOfServiceDate column to displays a count value for the total amount of displayed ServiceDate’s for each record. So since Nichol & Bradley have 1 record a piece on 03-Nov-08, I want a 2 to display in the CountOfServiceDate column. Not sure if this is possible the way I have my data structured.
Help Please! Thanks Big in advance.
Current query results (except the CountOfServiceDate column):
DayNum ClientID ServiceDate FamilyID CountOfServiceDate
3 Johnson, Nichol 03-Nov-08 Johnson Family, Mary & Robert 2
3 Johnson, Bradley 03-Nov-08 Johnson Family, Mary & Robert 2
4 Johnson, Nichol 04-Nov-08 Johnson Family, Mary & Robert 1
Current Failed Query:
SELECT DISTINCT [ClientLastName] & ", " & [ClientFirstName] AS ClientFullName, tblCareDay.ServiceDate, tblClients.ClientID,
(SELECT top 1 Count(*) FROM tblCareDay GROUP BY tblCareDay.ServiceDate) AS CountOfServiceDate
FROM (tblClients INNER JOIN tblCareDayRecord ON tblClients.ClientID = tblCareDayRecord.ClientID) INNER JOIN tblCareDay ON tblCareDayRecord.CareDayID = tblCareDay.CareDayID
GROUP BY [ClientLastName] & ", " & [ClientFirstName], tblCareDay.ServiceDate, tblClients.ClientID, tblClients.FamilyID, tblClients.ClientType
HAVING (((tblClients.FamilyID)=2) AND ((tblClients.ClientType)=3))
ORDER BY tblCareDay.ServiceDate;
I have Sub-Query SQL question.
I can’t figure out the correct Sub-Query SQL that will count the amount of ServiceDate records per day.
I want the CountOfServiceDate column to displays a count value for the total amount of displayed ServiceDate’s for each record. So since Nichol & Bradley have 1 record a piece on 03-Nov-08, I want a 2 to display in the CountOfServiceDate column. Not sure if this is possible the way I have my data structured.
Help Please! Thanks Big in advance.
Current query results (except the CountOfServiceDate column):
DayNum ClientID ServiceDate FamilyID CountOfServiceDate
3 Johnson, Nichol 03-Nov-08 Johnson Family, Mary & Robert 2
3 Johnson, Bradley 03-Nov-08 Johnson Family, Mary & Robert 2
4 Johnson, Nichol 04-Nov-08 Johnson Family, Mary & Robert 1
Current Failed Query:
SELECT DISTINCT [ClientLastName] & ", " & [ClientFirstName] AS ClientFullName, tblCareDay.ServiceDate, tblClients.ClientID,
(SELECT top 1 Count(*) FROM tblCareDay GROUP BY tblCareDay.ServiceDate) AS CountOfServiceDate
FROM (tblClients INNER JOIN tblCareDayRecord ON tblClients.ClientID = tblCareDayRecord.ClientID) INNER JOIN tblCareDay ON tblCareDayRecord.CareDayID = tblCareDay.CareDayID
GROUP BY [ClientLastName] & ", " & [ClientFirstName], tblCareDay.ServiceDate, tblClients.ClientID, tblClients.FamilyID, tblClients.ClientType
HAVING (((tblClients.FamilyID)=2) AND ((tblClients.ClientType)=3))
ORDER BY tblCareDay.ServiceDate;