i need to INSERT data with date from a table to another table with windows batch (.bat).
SET thedate='02/02/13'
mysql -e "INSERT INTO dest select str_to_date($thedate,'%d/%m/%Y') from source" thebase -uroot -ppassword`"
when i drag the .bat file to cmd window, the window show my code as :
SET thedate='02/02/13'
mysql -e "INSERT INTO dest select str_to_date($thedate,'m/Y') from source" thebase -uroot -ppassword"
the %d/%m/%Y has changed to m/Y so i get null value in table dest. When i run this query directly in phpmyadmin, it run well.
I use xampp 18.1 Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
In Windows batch, the syntax for variables is
%foo%, not$foo. You’re probably confusing it with bash. As such:$thedateis not a variable%d/%is considered an unsetd/variable%in%Yis considered an unmatched variable delimiter and gets ignoredYou can escape
%if you duplicate it:… prints:
I’d advise you against composing SQL strings through the command line interpreter if possible. It’s very difficult to get it right.