Reputation: 31
In a .bat file, I am trying to get the count from a database table and trying to assign it to a variable. But echo of the variable shows that the variable is getting assigned to the statement string value instead of the count. When I execute only the statement in command prompt I am able to see the count, which means the statement is correct. Need help in assigning this count to a variable.
Code Snippet:
SET x='mysql -uroot -pmysql -N testdatabase -e"select count(*) from test"'
echo "x :" %x%
Upvotes: 0
Views: 668
Reputation: 3864
In a batch file it's not that simple I'm afraid. You will need to call this strange for
syntax:
for /f "delims=" %%a in ('mysql -uroot -pmysql -N testdatabase -e"select count(*) from test"') do @set x=%%a
echo "x :" %x%
Or you may try Powershell script file which looks much nicer:
$x = & mysql -uroot -pmysql -N testdatabase -e"select count(*) from test"
"x : $x"
Upvotes: 1