user710502
user710502

Reputation: 11469

Mysql query throwing error

I am getting a :

You have an error in your sql syntax; check the manual that correspondes to....

here is my query. I do MSSQL, I am new to mysql .. Please help

    IF EXISTS (SELECT * FROM TIMESHEET WHERE EMPLOYEEID = '1' AND PERIODENDINGDATE = '2011-01-30')
   UPDATE TIMESHEET SET STATUSCODE = 'P', PERIODENDINGDATE = '2011-01-30', DEPARTMENTCODE = 'IT'
                        MINUTESMON = '200', MINUTESTUE= '200', MINUTESWED='200', MINUTESTHU='200'
                        MINUTESFRI='200', MINUTESSAT='200', MINUTESSUN='200'
ELSE
   INSERT INTO TIMESHEET (EMPLOYEEID, STATUSCODE, PERIODENDINGDATE, DEPARTMENTCODE, MINUTESMON, MINUTESTUE,
                          MINUTESWED, MINUTEDTHU, MINUTESFRI, MINUTESSAT, MINUTESSUN)
          VALUES ('1','P','2011-01-30','IT','200','200','200','200','200','200','200')  

Upvotes: 0

Views: 83

Answers (1)

Dan Grossman
Dan Grossman

Reputation: 52372

Unless this is part of a stored procedure or function or trigger, this simply isn't a valid form for a MySQL query. You can't just write freeform logic into a single query with MySQL.

You probably want to write an INSERT INTO...ON DUPLICATE KEY UPDATE query.

Upvotes: 1

Related Questions