By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,204 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,204 IT Pros & Developers. It's quick & easy.

how can i solve and how to fix to correct?

P: 1
This following is my code

Expand|Select|Wrap|Line Numbers
  1. SELECT staff.staffid, 
  2. staff.name, 
  3. attendance.checkintime, 
  4. attendance.checkouttime, 
  5. attendance.breakintime, 
  6. attendance.breakouttime, 
  7. attendance.latetime, 
  8. attendance.overtime, 
  9. attendance.transfees, 
  10. COUNT (paidvacation.staffid) AS Leave, 
  11. COUNT(attendance.staffid) AS Work 
  12. FROM attendance 
  13. INNER JOIN staff ON (staff.staffid = attendance.staffid) 
  14. INNER JOIN paidvacation ON (paidvacation.staffid = attendance.staffid) 
  15. WHERE (attendance.createdate>='$startdate' AND attendance.createdate<='$lastdate') GROUP BY attendance.staffid;
ERROR formed

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Leave,
COUNT(attendance.staffid) AS Work
FROM attendance
INNER JOIN staff ON ' at line 10
Oct 9 '14 #1
Share this Question
Share on Google+
2 Replies


P: 3
seems to be that you have extra space between
Expand|Select|Wrap|Line Numbers
  1. COUNT (paidvacation.staffid) 
count and open braces remove it and check,

Expand|Select|Wrap|Line Numbers
  1. SELECT staff.staffid,staff.name,attendance.checkintime,attendance.checkouttime,attendance.breakintime,attendance.breakouttime,
  2. attendance.latetime,attendance.overtime,attendance.transfees,COUNT(paidvacation.staffid) AS Leave,COUNT(attendance.staffid) AS Work
  3. FROM attendance INNER JOIN staff ON (staff.staffid = attendance.staffid) INNER JOIN paidvacation ON (paidvacation.staffid = attendance.staffid)
  4. WHERE (attendance.createdate>='$startdate' AND attendance.createdate<='$lastdate') GROUP BY attendance.staffid;
Oct 9 '14 #2

Expert 100+
P: 1,035
the problem is that LEAVE is a reserved word

Because of this it should not be used as an alias, or you should put double quotes around it:
Expand|Select|Wrap|Line Numbers
  1. [root@test]> select 1 Leave;
  2. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Leave' at line 1
  3. [root@test]> select 1 "Leave";
  4. +-------+
  5. | Leave |
  6. +-------+
  7. |     1 |
  8. +-------+
  9. 1 row in set (0.00 sec)
  10.  
  11.  
Oct 11 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.