hi all,

i have a little issue with SUM query from this table

UNIQUEID Date Production
engine1 01/12/1999 1440
engine1 01/01/2000 6061
engine1 01/02/2000 5152
engine1 01/03/2000 5347
engine1 01/04/2000 4642
engine1 01/05/2000 5264
engine1 01/06/2000 5247
engine2 01/07/1995 561
engine2 01/08/1995 3066
engine2 01/09/1995 2133
engine2 01/10/1995 2282
engine2 01/11/1995 2697
engine2 01/12/1995 3741
engine2 01/01/1996 4201
engine2 01/02/1996 4289
engine2 01/03/1996 4292
engine2 01/04/1996 4165

i want to SUM production from one UNIQUEID and date,

strQuery = "SELECT SUM(Production) FROM MONTHLYPROD WHERE UNIQUEID LIKE '"+engineName+"'";

when i use this query, i can get sum of production from engine1, but i want to make more specific, like SUM production from engine1 from date '01/12/1999' to '01,02,2000'

can anyone help me :D

Re: SUM query 80 80


strQuery = "
	SELECT SUM(`Production`) 
	WHERE	(STR_TO_DATE(`DATE`,'%m/%d/%Y') 
						STR_TO_DATE('01,02,2000', '%m,%d,%Y') 
		AND (`UNIQUEID` LIKE '"+engineName+"')";
Re: SUM query 80 80

uh oh, it's not working :(
am i doing any wrong?
i am using visual studio 2008 with ms.access as the data source

and the error is :

An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

Additional information: Undefined function 'STR_TO_DATE' in expression.

btw, thanks hielo for your reply

Re: SUM query 80 80

You posted this in MySQL. The syntax I gave you is for MySQL, NOT access.

strQuery = "
	SELECT SUM([Production]) as total
		AND ([UNIQUEID] LIKE '"+engineName+"')"
Re: SUM query 80 80

now everything works perfect :D
thanks for helping me hielo

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.