Basudev
Basudev

Reputation: 155

Facing issue during update in mysql

i have stored a value in a variable in shell. like below

app=$(mysql -uroot -p123456 -e 'SELECT applicant FROM `leave` where status="Applied" and applying_date= curdate()' comviva|tail -1);

but using this variable if i want to update any column i am facing a error. below is the error. Update Command:

mysql -uroot -p123456 -e "update leave set status=\"pending\" where applicant=\"$app\"" comviva;

The error encountered:

ERROR 1064 (42000) at line 1: 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 set status="pending" where applicant="a"' at line 1

Upvotes: 0

Views: 34

Answers (2)

Ravinder Reddy
Ravinder Reddy

Reputation: 24012

Error was due to use of a Reserved Word, LEAVE in the statement, as an identifier.

So to use it as an identifier in your statement, use back ticks around it.

mysql -uroot -p123456 -e "update `leave` set status='pending' where applicant='$app'" comviva;

Upvotes: 1

Ilesh Patel
Ilesh Patel

Reputation: 2155

Please use this

mysql -uroot -p123456 -e "update leave set status='pending' where applicant='$app'" comviva;

Upvotes: 0

Related Questions