Re: osql in a cmd file, with SQL statements coming from the same cmd f
From: David Gugick (davidg-nospam_at_imceda.com)
Date: 12/08/04
- Next message: Sam: "Search entire database for a specific value"
- Previous message: Adam Machanic: "Re: How do people sort their stored procedures"
- In reply to: forestial: "osql in a cmd file, with SQL statements coming from the same cmd f"
- Next in thread: forestial: "Re: osql in a cmd file, with SQL statements coming from the same c"
- Reply: forestial: "Re: osql in a cmd file, with SQL statements coming from the same c"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 7 Dec 2004 20:45:53 -0500
forestial wrote:
> I want to run osql in a command file. Instead of having the SQL
> statements in a separate .sql file, using "osql -i file.sql..." I
> want to have the SQL statements right there in the command file.
> This way my command file is self-contained; only one file to worry
> about instead of separate cmd and sql files.
>
> In unix (or more precisely in the bash shell) this would be done by
> what is called a "here document". Conceptually:
>
> osql <<END_OF_SQL
> select * from customers
> select * from suppliers
> END_OF_SQL
>
> Any way to do this with OSQL, or by some CMD.EXE trick?
Sure. You can create a CMD file to run the batch with contents like
this: Substitute -E to use a trusted connection which is recommended
over putting user id and password in the file. Use a capital Q to exit
OSQL immediately. Separate batches with Go and use -O for an output
file.
osql -Uuser -Ppassword (or -E) -Sserver -Q"Select id from sysobjects go
select id from sysindexes" -ooutput.txt
-- David Gugick Imceda Software www.imceda.com
- Next message: Sam: "Search entire database for a specific value"
- Previous message: Adam Machanic: "Re: How do people sort their stored procedures"
- In reply to: forestial: "osql in a cmd file, with SQL statements coming from the same cmd f"
- Next in thread: forestial: "Re: osql in a cmd file, with SQL statements coming from the same c"
- Reply: forestial: "Re: osql in a cmd file, with SQL statements coming from the same c"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|