This is something very old that I used when I had a script which invoked fdisk to create partitions, because fdisk requires user interaction.
Code:
create_partitions()
{
cat<<EOF|sudo fdisk $1
n
p
1
1
+32M
n
p
2
w
EOF
}
I found the concept to do the passing of the arguments somewhere on the web and refined it to do what I needed.
Perhaps this technique will work for injecting commands to the SQL part of your script.
To know more or help you more, we'd need to see the part of the script which calls SQL as well as know what you need to type into the SQL application to fulfill the needs for it.
As best as you can, instead of trying this, if you can find ways to invoke SQL with arguments in the command line which make it run to completion, that would be a more clean option.
And in direct contradiction to what I just wrote ... I got this working long ago and never modified it. There may be a better way.