Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys is there any way on where can i execute my query faster ? here it us:

What I have tried:

select count(distinct(str_to_date(dwardate,'%m/%d/%Y'))) as tdays ,staffhouse,mealallowance,transporallowance " & _
",staffhouseto,mealto,transpoto,transpoeffective From employees " & _
"inner join EAC on eac.employeesid = employees.employeesid " & _
"inner join tbldwardetails on tbldwardetails.Employeesid = employees.employeesID " & _
"Inner join employeesAttendance on employeesAttendance.Employeesid = employees.employeesID " & _
"WHERE LOGTIMEIN <> '' AND LOGTIMEOUT<> '' AND Remarked <> 'OFFSET FROM' AND str_to_date(dwardate,'%m/%d/%Y') >= '" & dafrom & "' and str_to_date(dwardate,'%m/%d/%Y') <= '" & dato & "' and EMPLOYEES.employeesid = " & empids & " group by dwardate"
Posted
Updated 31-Jul-17 20:50pm
Comments
Graeme_Grant 1-Aug-17 2:06am    
You have a lot of joins ... Have you viewed the query plan? Do you have indexes for the fields/columns that you are joining on?

1 solution

Get rid of those str_to_date(dwardate,'%m/%d/%Y'), use the proper datetime type instead, and use a parameterized query.
Functions in WHERE clauses enforce table scans (instead of index lookups), and parameterized queries help you overcome formatting issues and SQL injection issues.
 
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