Reputation: 996
I'm hope I doing everything in the right path. I wrote a shell script, if the condition matched, it will run update query.
#!/bin/bash
mysql -u root -pPassword <<rc
use rc;
SELECT *,
CASE
WHEN cutoff_dt IS NULL
THEN
UPDATE rc SET cutoff_dt = '2017-03-21 00:00:00.0'
ELSE 'NOT NULL'
END
from rc
WHERE business_date = '2017-03-21 16:50:29.032';
rc
Unfortunately, I get error
ERROR 1064 (42000) at line 2: 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 rc SET cutoff_dt = '2017-03-21 00:00:00.0'
ELSE ' at line 5
Latest code
The answer given doesn't helped ! Maybe I'm doing wrong ?
#!/bin/bash
mysql -u root -pPassword <<rc
use rc;
SELECT *,
CASE
WHEN cutoff_dt IS NULL
THEN
UPDATE mepslog
SET cutoff_dt = '2017-03-21 23:57:19'
WHERE business_date = '2017-03-21 00:00:00.000'
AND cutoff_dt IS NULL
END
from rc
WHERE business_date = '2017-03-21 00:00:00.000';
rc
Upvotes: 0
Views: 88
Reputation: 181
You cant mix such queries. Instead you would extend the query's where
-clause.
A working update would look like as following:
UPDATE rc
SET cutoff_dt = '2017-03-21 00:00:00.0'
WHERE business_date = '2017-03-21 16:50:29.032'
AND cutoff_dt IS NULL
Upvotes: 4