shellisqlisqlquery

How to execute an SQL statement stored in a shell script variable using isql


So, I am trying to execute an SQL statement stored in a shell script variable using isql

Generic code attached.

SQL="select * from Student"

EMPLOYEES=`isql -U $USERNAME -P $PASSWORD -D $DATABASE -S $SERVER<<EOF
$SQL
go

However on executing this, I get an error such as: Incorrect syntax near the keyword 'Select' and Incorrect suntax near '='

Anyone knows how to execute the SQL query directly stored in a variable from isql?


Solution

  • Try in this way:

    EMPLOYEES=`echo "$SQL" | isql -U $USERNAME -P $PASSWORD -D $DATABASE -S $SERVER`