Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pls help with diagnosing this insert/update statement?

Status
Not open for further replies.

BobMCT

IS-IT--Management
Sep 11, 2000
756
US
Ever run into a brick wall. This (seemingly) simple sql statement is failing with a syntax error. I've checked field names against the table definitions and they look to be exact. The content of the data is also as expected. I've searched for samples and what I find all appear similar to what I have. So would someone please point out where the syntax might be in error? btw I'm using 5.5.44 and this must run on MariaDB as well. Any pointers - THANKS!

INSERT INTO alminfo_mbsaqip.patients ( id, mbsaqip_case_number, acs_nsqip_case_number, idn, firstname, lastname )
VALUES ( '5', '01234', '54321', '56789', 'Leslie', 'Liverpool' )
ON DUPLICATE KEY UPDATE mbsaqip_case_number = '01234', acs_nsqip_case_number = '54321',
idn = '56789', firstname = 'Leslie', lastname = 'Liverpool' WHERE id = '5';

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 'WHERE id = '5'' at line 4

I've also tried it without the WHERE on the update seeing how its a duplicate anyway. Same error message pointing to an earlier place in the statement.

Here's the definition:

CREATE TABLE IF NOT EXISTS `alminfo_mbsaqip`.`patients` (
`id` INT NOT NULL,
`mbsaqip_case_number` VARCHAR(45) NULL,
`acs_nsqip_case_number` VARCHAR(45) NULL,
`idn` VARCHAR(45) NULL,
`firstname` VARCHAR(45) NULL,
`lastname` VARCHAR(45) NULL,
`assessment_date` DATE NULL,
`patient_alive` INT NULL,
`exam_by_bariatric_physician_or_pa_np` INT NULL,
`seen_by_clinician` INT NULL,
`sleep_apnea` VARCHAR(45) NULL,
`gerd_req_meds` VARCHAR(45) NULL,
`hyperlipidemia` VARCHAR(45) NULL,
`hypertension` VARCHAR(45) NULL,
`diabetes` VARCHAR(45) NULL,
`follow_up_noshow` VARCHAR(45) NULL,
`phone_call_placed` VARCHAR(45) NULL,
`letter_sent` VARCHAR(45) NULL,
`transfer_to_specalist` VARCHAR(45) NULL,
`patient_refuse_long_term_fu` INT NULL,
`lost_to_follow_up` INT NULL,
`date_of_death` DATE NULL,
`death_related_to_operation` INT NULL,
`cause_of_death` VARCHAR(45) NULL,
`comments` MEDIUMTEXT NULL,
`timestamp` VARCHAR(45) NULL,
`surgeon` VARCHAR(45) NULL,
`surgery_date` VARCHAR(45) NULL,
`facility` VARCHAR(45) NULL,
`alm_patient_id` VARCHAR(45) NULL,
`procedure` VARCHAR(45) NULL,
`comment` MEDIUMTEXT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB;
 
Hi

BobMCT said:
I've also tried it without the WHERE on the update
Insist on that. There is no [tt]where[/tt] clause for [tt]on duplicate key update[/tt]. Without [tt]where[/tt] your code works fine for me on MySQL 5.6.28.

Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top