WHERE STATEMENT PROBLEMS

Im doing a report on total sales, however my statement below will return values that are equal to both fields ONLY.

For example I want to do a query using two text boxes 'from' and 'to 'and count the total sales between the product dates 'Veh_Tyres_Date' and Veh_Parts_Date and 'Veh_Tyres Price' and Veh_Parts Price'

. however it works but if for example I do a search for 01/05/2015 from 31/05/2015 it will not return anything if the second field doesnt contain a sales date between that period. Help

SELECT tblVehicles.Veh_Parts, tblVehicles.Veh_Parts_Date, tblVehicles.Veh_Tyres, tblVehicles.Veh_Tyres_Date
FROM tblVehicles
WHERE (((tblVehicles.Veh_Parts_Date) Between [Enter From Date] And [Enter To]) 
AND ((tblVehicles.Veh_Tyres_Date) Between [Enter From Date] And [Enter To]));
May 22nd, 2015 1:46am

Hi,

You need OR instead AND.

SELECT tblVehicles.Veh_Parts, tblVehicles.Veh_Parts_Date, tblVehicles.Veh_Tyres, tblVehicles.Veh_Tyres_Date
FROM tblVehicles
WHERE (((tblVehicles.Veh_Parts_Date) Between [Enter From Date] And [Enter To]) 
OR ((tblVehicles.Veh_Tyres_Date) Between [Enter From Date] And [Enter To]));

Free Windows Admin Tool Kit Click here and download it now
May 22nd, 2015 2:23am

Good day,

Please post some sample data and the result that you want to get.

Post a query to create the relevant table and a query to insert the sample data. This will help us to reproduce your issue and to understand what you have and what you need.

Thanks

May 22nd, 2015 3:08am

Hi NHSTech,

According to your description, are there two date columns in your table, Veh_Parts_Date and Veh_Tyres_Date? Your query would return the rows with both those columns in the given time span. 

The suggestion using OR instead of AND from Vitaliy sounds reasonable, if that is not what your want, as Pituach suggested, please post some sample data and expected output.

If you have any question, feel free to let me know.


Free Windows Admin Tool Kit Click here and download it now
May 25th, 2015 1:58am

Did you convert those data into datetime data type? 

Make sure you are not comparing those data as string. 

May 25th, 2015 2:14am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics