Monday, July 02, 2007

Using UNIX Redirection Symbols for Sybase

You can send input to the isql command via the command line interface. Note the ESOFT string is arbitrary. I have also included reading SQL commands from a file. Here are the examples.

# isql -Usa -Pyourpassword -Syourserver_name << ESOFT > myoutput
use esoftdb
go
select count(*) from mysoft_table
go
ESOFT

View the results
# cat myoutput

Read SQL from a file
# isql -Usa -Pyourpassword -Syourserver_name < ESOFTFILE > myoutput

View the results
# cat
myoutput

2 comments:

Anonymous said...

If you want to run Sybase TSQL commands in a shell script somewhere you can do it as follows (in your script):

isql -Usa -Pyourpassword -Syourserver_name <<-BOF
use esoftdb
go
select count(*) from mysoft_table
go
BOF

Also, reading from file can be a bit easier:

isql -Usa -Pyourpassword -Syourserver_name -i myoutput

Cheers,
David

esofthub said...

David, Great tip!