Click here to Skip to main content
15,916,702 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
the query I am using in MS Access 2010 is:
SQL
SELECT format( DateValue(Trans.Dt),"dd/MM/yyyy")   AS DateOfAttendance, Format(Min(Trans.Dt),"Long Time") AS InTime, Format(Max(Trans.Dt),"Long Time") AS OutTime,  Trans.EmpID
FROM Trans
WHERE (((DateValue([Trans].[Dt])) between ('4/1/2014')and('4/30/2014') and empid="0044"))
GROUP BY DateValue(Trans.Dt), Trans.EmpID, Trans.CardID;
Posted
Comments
Vinay Mistry 28-Aug-14 3:49am    
Please complete your question in body part.
Herman<T>.Instance 28-Aug-14 6:37am    
set the date values in varchar in order of yyyy/mm/dd ->
between ('4/1/2014')and('4/30/2014') should become
between ('2014/04/01') and ('2014/04/30')

1 solution

In Access queries use the # symbol to delimit literal dates. Converting dates to strings is not a great way to do filtering, sorting and comparisons. The Microsoft date format is internally stored as a floating point number and is more efficient for these operations than text. So your query should read:

SELECT format( DateValue(Trans.Dt),"dd/MM/yyyy") AS DateOfAttendance, Format(Min(Trans.Dt),"Long Time") AS InTime, Format(Max(Trans.Dt),"Long Time") AS OutTime, Trans.EmpID
FROM Trans
WHERE (((DateValue([Trans].[Dt])) between (#4/1/2014#)and(#4/30/2014#) and empid="0044"))
GROUP BY DateValue(Trans.Dt), Trans.EmpID, Trans.CardID;

This way there are no implicit casts to or from a string for the where clause everything is carried out using abstract dates.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900