summarize by date in a sql statement - TechRepublic
General discussion
December 23, 2005 at 06:36 AM
mark.peterson1

summarize by date in a sql statement

by mark.peterson1 . Updated 20 years, 6 months ago

I am trying to write a report in Excel, I am using 3 tables from a sql server database, one table has tech labor by invoice which I want to sum by date, the 2nd table is Tech name and id #,
the 3rd table is time clock entry by date. I have been having a hard time trying to get the 1st table summarized by date so I can join the 3 tables together. Here is an example of part of the query for the first table and the 2nd table.
SELECT DISTINCT Min(INSTHIST.DATESTAMP) AS ‘DATE’, INSTHIST.COMPANY AS ‘STORE’, INSTHIST.LABOR_TIME AS ‘LABOR’, MECHANIC.MECHANIC_NAME AS ‘NAME’
FROM VastOffice.dbo.INSTHIST INSTHIST, VastOffice.dbo.MECHANIC MECHANIC
WHERE MECHANIC.MECHANIC_NUMBER = INSTHIST.MECHANIC_NUMBER
GROUP BY INSTHIST.COMPANY, INSTHIST.LABOR_TIME, MECHANIC.MECHANIC_NAME, INSTHIST.DATESTAMP, INSTHIST.INSTALLER
HAVING (INSTHIST.DATESTAMP>={ts ‘2005-11-26 00:00:00’}) AND (INSTHIST.LABOR_TIME<>0.0) AND (INSTHIST.INSTALLER=1)
ORDER BY Min(INSTHIST.DATESTAMP) DESC

This discussion is locked

All Comments