I need to automatize an sql script via bash. I'm asking about how to use bash variable in an sql command use by freeTDS. Here is my command and the code below :
echo "Declare @montant int =$mobile ,@categorie varchar(12) = 'mobile',@nom varchar(50) = '%'+$filename+'%',@temps varchar(12) = $Tmobile
Print @montant
Print @categorie
Print @nom
Print @temps
EXEC Test @montant, @categorie, @nom, @temps
go
" > tempfile
I use to load my sql function "Test" with parameters that come from my bash script. But i dunno why, the script don't recognize them. I already tried with the option -t on my command ("-t --mobile=$mobile").
tsql -H $DB_HOSTNAME -p $DB_PORT -U $DB_USER -P $DB_PWD -D $DB_NAME -o fvq
< tempfile
The actual error is :
Msg 126 (severity 15, state 1) from ARAGORN\GENESYS Line 2:
"Invalid pseudocolumn "$filename"."
Msg 137 (severity 15, state 2) from ARAGORN\GENESYS Line 4:
"Must declare the scalar variable "@montant"."
Msg 137 (severity 15, state 2) from ARAGORN\GENESYS Line 5:
"Must declare the scalar variable "@categorie"."
Msg 137 (severity 15, state 2) from ARAGORN\GENESYS Line 6:
"Must declare the scalar variable "@nom"."
Msg 137 (severity 15, state 2) from ARAGORN\GENESYS Line 7:
"Must declare the scalar variable "@temps"."
Msg 137 (severity 15, state 2) from ARAGORN\GENESYS Line 9:
"Must declare the scalar variable "@montant"."
Thanks !