Sql statement with "group by" and "having"
Hi,
Could anybody help me please what's wrong with my SQL statement?
I have three tables in my database. I have a dataset and three tableAdapters and want to write the sql command string for retrieving the data from the database with the following requirements:
string comstring="SELECT NOVI.GBR, NOVI.AB, NALOG1.DATA, Min(NALOG1.POCKM) AS MinOfPOCKM, Max(NALOG1.KRAJKM) AS MaxOfKRAJKM, (Max(NALOG1.KRAJKM)-Min(NALOG1.POCKM)) AS RAZLIKA FROM (NALOG1 INNER JOIN MAGACIN ON NALOG1.GBRV=MAGACIN.GBR) INNER JOIN NOVI ON NALOG1.GBRV=NOVI.GBR GROUP BY NOVI.GBR, NOVI.AB, NALOG1.DATA
HAVING (((NOVI.GBR)>="1081" And (NOVI.GBR)<="1149") AND ((NOVI.AB)="1") AND ((NALOG1.DATA)=#10/31/2011#))";
Thanks in advance.