troubleshooting Question

What is wrong with this SQL INSERT?

Avatar of Bruce Gust
Bruce GustFlag for United States of America asked on
MySQL ServerSQL
17 Comments1 Solution27 ViewsLast Modified:
Here's my SQL:

select 
   case 
      when 
         (select count(*) from tasks t where t.CUSTID='DPR01' and t.INTID='INT0001'>0)
      then
         UPDATE tasks_master_tracker_idb SET 
            CLIENT_CONTACT = (SELECT t.CLIENT_CONTACT FROM tasks t WHERE t.CUSTID='DPR01' AND t.INTID='INT0001'),
            COMPLEXITY = (SELECT t.COMPLEXITY FROM tasks t WHERE t.CUSTID='DPR01' AND t.INTID='INT0001'),
            CREATED_BY = (SELECT t.CREATED_BY FROM tasks t WHERE t.CUSTID='DPR01' AND t.INTID='INT0001'),
            CUSTID = (SELECT t.CUSTID FROM tasks t WHERE t.CUSTID='DPR01' AND t.INTID='INT0001'),
            DIRECTION = (SELECT t.DIRECTION FROM tasks t WHERE t.CUSTID='DPR01' AND t.INTID='INT0001'),
            INTEGRATION_ID = (SELECT t.INTID FROM tasks t WHERE t.CUSTID='DPR01' AND t.INTID='INT0001'),
            INTEGRATION_NAME = (SELECT t.NAME FROM tasks t WHERE t.CUSTID='DPR01' AND t.INTID='INT0001'),
            INTEGRATION_STATUS = (SELECT t.STATUS FROM tasks t WHERE t.CUSTID='DPR01' AND t.INTID='INT0001'),
            INTEGRATION_TYPE = (SELECT t.PROJ_TYPE FROM tasks t WHERE t.CUSTID='DPR01' AND t.INTID='INT0001'),
            VENDOR = (SELECT t.VENDOR FROM tasks t WHERE t.CUSTID='DPR01' AND t.INTID='INT0001')
            WHERE
            CUSTID='DPR01'
                AND
                INTEGRATION_ID='INT001'
      else
         INSERT into tasks_master_tracker_idb (
         CLIENT_CONTACT, COMPLEXITY, CREATED_BY, CUSTID, DIRECTION,
         INTEGRATION_ID, INTEGRATION_NAME, INTEGRATION_STATUS, INTEGRATION_TYPE, VENDOR
         )
            SELECT t.CLIENT_CONTACT, t.COMPLEXITY, t.CREATED_BY, t.CUSTID, t.DIRECTION,
            t.INTID, t.NAME, t.STATUS, t.PROJ_TYPE, t.VENDOR 
            FROM
            tasks t
            WHERE 
            t.CUSTID='DPR01'
            AND
            t.INTID='INT0001'
      end
I'm getting an error that says, "Error Code: 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 'UPDATE tasks_master_tracker_idb SET      CLIENT_CONTACT = (SELECT t.CLIENT_CONTA' at line 6

Not sure what's wrong or how to fix it.

Any ideas?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 17 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 17 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros