1

I have a file that contains several SQL queries.

Can I somehow run them via isql (I'm doing the calls from Bash script, so no access to Perl DBI or JDBC)

I tried piping them into isql command via echo /my/file | isql -my-other-parameters but that didn't work.

user25235
  • 13
  • 1
  • 3

3 Answers3

0

Yes.

  • If you're running ISQL in interactive mode, you can load an entire contents of the file using :r my-filename command from > prompt.

  • From Bash script, it's also possible to do - but you need to carefully make sure that

    1. The SQL file you are piping in has a go statement at the end. That is a VERY common cause of issues like the one you mentioned.

    2. That statement has a newline after it.

    From a script, you can do it 2 ways: Pass on STDIN via a pipe/redirect; OR, pass in the file name via isql's -i parameter

DVK
  • 126,886
  • 32
  • 213
  • 327
0

In my case it was isq -n for a piped query to work.

Umair A.
  • 6,690
  • 20
  • 83
  • 130
0
isql -U $DB_USR -P $DB_PWD -S $DB_PATH -D $DB_NAME -w 500 < $FILE
rene
  • 41,474
  • 78
  • 114
  • 152
SDF
  • 11
  • 3
  • While this code snippet may solve the question, [including an explanation](//meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. Please also try not to crowd your code with explanatory comments, this reduces the readability of both the code and the explanations! – rene Aug 14 '17 at 17:07