473,395 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

osql batch processing without -i

Hi,
I have just started using MSSQL and the DOS environment at work. I have
a lot of experience with Sybase and the UNIX environment, but this is a
whole new ball of wax.
I'd like to use osql from a batch file to log into the dataserver and
run a fairly long list of SQL and then exit. I don't want to have a bunch
of SQL files sitting around that I have to use the -i option to run, and
I'd rather not create temporary SQL files like this.

echo "exec sp_who2" >tmp.sql
echo "select * from....... " >>tmp.sql
osql -E -S <DATASERVER> -n -w999 -i tmp.sql
del tmp.sql

I can't use the -Q option, of course because as I said, I'll be writing
quite a few lines of SQL, and it won't all fit on the one line, or at least
it wouldn't be pretty if I did.

In UNIX, I can simply execute the following from either the command line
or in
a script.

isql -S<DATASERVER> -U<USER> <<-EOF

sp_who
go
select * from .....
go
EOF --EOF is the isql session terminator exits me back to the command line.

This behavior does not appear to work with OSQL. There is a -O option
which help mentions, and that talks about disabling the EOF terminator for
batch processing, but I wasn't able to find any usage or examples on the net
where someone is using EOF to terminate their OSQL SQL batch.

This is what help listed.
[-O use Old ISQL behavior disables the following]
<EOF> batch processing
Auto console width scaling
Wide messages
default errorlevel is -1 vs 1
Any help you could offer would be appreciated. Thanks.

Darren


Jan 17 '06 #1
2 5233
On Mon, 16 Jan 2006 18:44:19 -0600, <dp********@comcast.net> wrote:

(snip)
In UNIX, I can simply execute the following from either the command line
or in
a script.

isql -S<DATASERVER> -U<USER> <<-EOF

sp_who
go
select * from .....
go
EOF --EOF is the isql session terminator exits me back to the command line.

This behavior does not appear to work with OSQL.
Hi,

It's not OSQL, it's Windows/DOS that is causing the difference. In UNIX,
utilities take their input from STDIN, which is either the next line in
the script (if run from a script) or the next line entered on the
console (if run from a console).

The same thing happens if you create a script (testme.bat) with the
following content:

copy con test.txt
This won't work

Execute it. The copy con command is started and the console will wait
for your input. Type one or more lines, then type Ctrl-Z (the EOF
marker). You'll next see an error because "Thins won't work" is not a
valid DOS command.

An equivalent script in Unix would enter "This won't work" in the file
test.txt.
Any help you could offer would be appreciated.


I think that you'll have to settle for either a bunch of commonly used
SQL script files, or for dynamically building the SQL script using a
bunch of redirected echo statements.

--
Hugo Kornelis, SQL Server MVP
Jan 17 '06 #2

"Hugo Kornelis" <hu**@perFact.REMOVETHIS.info> wrote in message
news:ra********************************@4ax.com...
On Mon, 16 Jan 2006 18:44:19 -0600, <dp********@comcast.net> wrote:

(snip)
In UNIX, I can simply execute the following from either the command lineor in
a script.

isql -S<DATASERVER> -U<USER> <<-EOF

sp_who
go
select * from .....
go
EOF --EOF is the isql session terminator exits me back to the command line.
This behavior does not appear to work with OSQL.
Hi,

It's not OSQL, it's Windows/DOS that is causing the difference. In UNIX,
utilities take their input from STDIN, which is either the next line in
the script (if run from a script) or the next line entered on the
console (if run from a console).

The same thing happens if you create a script (testme.bat) with the
following content:

copy con test.txt
This won't work

Execute it. The copy con command is started and the console will wait
for your input. Type one or more lines, then type Ctrl-Z (the EOF
marker). You'll next see an error because "Thins won't work" is not a
valid DOS command.

An equivalent script in Unix would enter "This won't work" in the file
test.txt.
Any help you could offer would be appreciated.


I think that you'll have to settle for either a bunch of commonly used
SQL script files, or for dynamically building the SQL script using a
bunch of redirected echo statements.


Thanks for the Info Hugo. I was afraid of that. I'm used being able to
do whatever I want in UNIX, so DOS seems to be a bit of a step back for me.
I did just download a version of sed for DOS, which I'm really excited
about. :) I also have a VB .net class next week, so I'm hoping to pick up
some tricks in there. Thanks again.

Darren
--
Hugo Kornelis, SQL Server MVP

Jan 20 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ajay Garg | last post by:
I am running the following OSQL command and capturing the return code for the error .Whenver i have an error like server not exists or uable to login I get a return code of 1 for the...
2
by: second714 | last post by:
Hi, I have several big tables with rows more than 25 mil rows and to update/delete/insert data in these tables, it can take minutes. I use BULK Insert/DELETE/Update with osql. While I run one of...
24
by: LineVoltageHalogen | last post by:
Greetings All, I was hoping that someone out there has run into this issue before and can shed some light on it for me. I have a stored procedure that essentially does a mini ETL from a source...
1
by: vbnetrookie | last post by:
Hi all, This is my first batch file and I want to query a database and output it in a textfile. Up to now that works, the only problem is the formatting in the text file. It's all screewed...
0
by: theintrepidfox | last post by:
Dear Group I'd be grateful if you can help me with the following. I'm trying to connect to an instance of MSDE called BALTD. The instance has SQL authentication enabled and the service is...
4
by: pb648174 | last post by:
We have a very long and complicated SQL script which we run to upgrade a version of our software from old to new. It works great in Query Analyzer, but when run through osql it takes errors on...
5
by: mike | last post by:
I have a question. I am doing some work for someone and I have a batch file that they can run that will execute an OSQL line and a DTSRUN line. In both lines I run them using the /S /U /P...
5
by: gopal | last post by:
Hi I am running a OSQL utility from my console application . iam trying to install a huge SQL file of 5MB, i debugged my code and the application is not responding at the following line of code...
1
by: Tina888 | last post by:
I am running osql command that goes and grabs files from my folder and runs one script at a time and loops though all the files in that folder. Most of the files and simple inserts or creation of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.