0

I want to get the output of the following nested query into a variable in the bash script as follows.

count=SELECT count(*) FROM a
WHERE TRIM(REQUEST_STATUS) IN ('d','e','v') AND
(abc IS NULL) AND EXISTS (SELECT 1 FROM n WHERE LOWER(NAME)=LOWER(a.LOGINNAME)));

please help.

Azmy
  • 181
  • 3
  • 17
  • Use a cmd line client of your choice - you do not tell us which database is concerned - and the backtick to get the output into a bash variable. See https://unix.stackexchange.com/questions/27428/what-does-backquote-backtick-mean-in-commands for backtick. – Michal Jan 13 '20 at 17:13
  • You also don't tell us where your script is and where your database is. Nonetheless, I must candidly say that the *easiest* way to get this done would be to use a scripting language other than Bash. For instance, if the first line of your command file was, say, `#!/usr/bin/php`, then the shell would silently use PHP to handle your script ... now written in PHP ... and the end-user would be none the wiser. The built-in scripting of Bash is very primitive, and attempts like this one to make it do things it wasn't designed for get VERY messy VERY fast. – Mike Robinson Jan 13 '20 at 17:25
  • Assuming you know what client you want to use, this is a duplicate of https://stackoverflow.com/q/4651437/1126841. However, unless your query really is static and you aren't try to parameterize it, `bash` is the wrong language in which to be constructing dynamic queries. – chepner Jan 13 '20 at 17:26

0 Answers0