Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

isql from batch file

Status
Not open for further replies.

TheJFM

Programmer
Jun 13, 2002
65
GB
The following isql runs fine from the command line

isql -Snnnnnn -Unnnnnn -Pnnnnn -Dnnnnn -innn.sql -onnnn.txt

If I want to call it as part of a batch file how would I go about it?

Thanks in advance

 
Hi

Can you give more details as to what you mean "call it from a batch file?"

I'll make a simple assumption in that you may want to run queries 'through' that connection.

Try this..
-Use the -i and -o options to specify input and output files for your queries.

-You can also use Unix redirection methods of 'piping' commands into 'isql' to be executed.
Code:
ex: isql -Uuser -Ppass -Sserver < createTable.sql > results.txt
This will run the createTable script and output any results to the results.txt file.

- You can also use the &quot;perl style&quot; standard input to tell isql to take info from the command line and pipe the rsults to a file.
Code:
ex: isql -Uuser -Ppass -Sserver <<EOF > results.txt
(Then on command line type: select * from blah <enter>)
This will start the isql shell in the backgound and take any input typed in as sql commands. It executes the command and redirects them to results.txt

Now I can only hope this is what you needed to know.

:)

 
Thanks

I am running it through a windows environment.

I want to schedule a series of isql from a file called nnnn.bat.

I pasted the isql that ran successfully from the command line but this did not work and returned the following error to the output file

'tbl_nnnnnnnn not found. Specify owner.objectname or use sp_help to check whether
the object exists (sp_help may produce lots of output).'



 
Hi

Ah, you 'may' have to specify DATABASE_NAME.dbo.table_nnnnnn as the name of the table.

These commands DO run if you are 'inside' isql though? If so, paste the code and I'll see what I can figure out from tt.

In addition I beleive you can use the < and > redirection operators in windows as well as in unix.
 
Thanks ever so much

The full table name in the sql input file worked fine

I can now sleep this weekend ;-)

 
Glad I could help.

As a side note your problem 'may' be because you didn't setup a defaultDB in your profile. So when you connect through the batch it's not sure WHICH db the table is in.

You can fix this like so.

sp_modifylogin your_login_name, &quot;Defdb&quot;, table_to_be_default

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top