473,657 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ISQL and OSQL Output Lines Wrapped Around at 256 Characters?

I am trying to use a command line program to run a stored procedure
that generates output in a comma-delimitted format. Somehow, ISQL or
OSQL always wrap the lines at 256 characters. I believe this has
something to do with the column width switch (-w). But enlarging the
column width to 800 characters max still doesn't help. The following
is a stored procedure that is essentially doing what my stored
procedure is doing:

create procedure MyTest as
set ansi_padding on
set nocount on

declare @sTest varchar(300)

-- Output three lines. Each line has 259 characters.

select @sTest = "1234 6789 ... 1234 6789"
print @sTest

select @sTest = "1 3 5 7 9 ... 1 3 5 7 9"
print @sTest

select @sTest = "1 3 5 7 9 ... 1 3 5 7 9"
print @sTest

set nocount off
return( 0 )

I invoke this stored procedure using this command:

isql -SMyDbSrv -E -dMyDb -w800 -x800 -h-1 -n -Q"exec MyTest"
-oMyTest.txt
-- or --
osql -SMyDbSrv -E -dMyDb -w800 -h-1 -n -Q"exec MyTest" -oMyTest.txt

But they have the same problem. The output lines all wrap around at
256 characters.

Strangely, if I store the result in a temporary table, and then use
SELECT to output the result from the temporary table, I will not have
that problem. Seem like the "-w" switch only works for output from
tables, but not for output coming from PRINT. Unfortunately, using
this approach has another set of problems (one blank space in front of
each line, "number-of-rows affected" shows up at the bottom).
Therefore, I would like to stick with using PRINT statements to output
the result.

Please suggest a way to fix this line-wrapping-around problem.

Thanks.

Jay Chan
Jul 20 '05 #1
5 23351
ja******@hotmai l.com (Jay Chan) wrote in message news:<c7******* *************** ***@posting.goo gle.com>...
I am trying to use a command line program to run a stored procedure
that generates output in a comma-delimitted format. Somehow, ISQL or
OSQL always wrap the lines at 256 characters. I believe this has
something to do with the column width switch (-w). But enlarging the
column width to 800 characters max still doesn't help. The following
is a stored procedure that is essentially doing what my stored
procedure is doing:

create procedure MyTest as
set ansi_padding on
set nocount on

declare @sTest varchar(300)

-- Output three lines. Each line has 259 characters.

select @sTest = "1234 6789 ... 1234 6789"
print @sTest

select @sTest = "1 3 5 7 9 ... 1 3 5 7 9"
print @sTest

select @sTest = "1 3 5 7 9 ... 1 3 5 7 9"
print @sTest

set nocount off
return( 0 )

I invoke this stored procedure using this command:

isql -SMyDbSrv -E -dMyDb -w800 -x800 -h-1 -n -Q"exec MyTest"
-oMyTest.txt
-- or --
osql -SMyDbSrv -E -dMyDb -w800 -h-1 -n -Q"exec MyTest" -oMyTest.txt

But they have the same problem. The output lines all wrap around at
256 characters.

Strangely, if I store the result in a temporary table, and then use
SELECT to output the result from the temporary table, I will not have
that problem. Seem like the "-w" switch only works for output from
tables, but not for output coming from PRINT. Unfortunately, using
this approach has another set of problems (one blank space in front of
each line, "number-of-rows affected" shows up at the bottom).
Therefore, I would like to stick with using PRINT statements to output
the result.

Please suggest a way to fix this line-wrapping-around problem.

Thanks.

Jay Chan


Unfortunately PRINT always wraps at 256 characters, and SELECT always
has a blank line between results in the output (but you shouldn't get
number of rows, since you've used -n). Or at least that appears to be
the behaviour, based on some quick experimentation . However, you could
use SELECT and strip out the blank lines before the results are
written to the file - here is a rather kludgy possible solution:

del MyTest.txt && for /F "usebackq eol= tokens=*" %i in (`osql -dMyDb
-E -h-1 -n -Q"exec dbo.MyTest" -w800 -s""`) do @echo %i >> MyTest.txt

Simon
Jul 20 '05 #2
> Unfortunately PRINT always wraps at 256 characters, and SELECT always
has a blank line between results in the output (but you shouldn't get
number of rows, since you've used -n). Or at least that appears to be
the behaviour, based on some quick experimentation . However, you could
use SELECT and strip out the blank lines before the results are
written to the file - here is a rather kludgy possible solution:

del MyTest.txt && for /F "usebackq eol= tokens=*" %i in (`osql -dMyDb
-E -h-1 -n -Q"exec dbo.MyTest" -w800 -s""`) do @echo %i >> MyTest.txt


Thanks for the info about the fact that PRINT always wrap around at
256 characters.

Seem like I will have to use SELECT instead of PRINT. And then write
another program to remove the leading blank space and the "(# of rows
affected)" message from the output.

Somehow, '-n' doesn't work. It doesn't remove the "(# of rows
affected)" message from the end of the result. Actually, I don't
really know what '-n' is supposed to do. ISQL/OSQL output the same
thing regardless I use '-n' or not.

Oh well...

Jay Chan
Jul 20 '05 #3
Hi

You may be better using BCP (or DTS) to generate these files.

To remove the count use SET NOCOUNT ON in your script.

John

"Jay Chan" <ja******@hotma il.com> wrote in message
news:c7******** *************** ***@posting.goo gle.com...
Unfortunately PRINT always wraps at 256 characters, and SELECT always
has a blank line between results in the output (but you shouldn't get
number of rows, since you've used -n). Or at least that appears to be
the behaviour, based on some quick experimentation . However, you could
use SELECT and strip out the blank lines before the results are
written to the file - here is a rather kludgy possible solution:

del MyTest.txt && for /F "usebackq eol= tokens=*" %i in (`osql -dMyDb
-E -h-1 -n -Q"exec dbo.MyTest" -w800 -s""`) do @echo %i >> MyTest.txt


Thanks for the info about the fact that PRINT always wrap around at
256 characters.

Seem like I will have to use SELECT instead of PRINT. And then write
another program to remove the leading blank space and the "(# of rows
affected)" message from the output.

Somehow, '-n' doesn't work. It doesn't remove the "(# of rows
affected)" message from the end of the result. Actually, I don't
really know what '-n' is supposed to do. ISQL/OSQL output the same
thing regardless I use '-n' or not.

Oh well...

Jay Chan

Jul 20 '05 #4
Jay Chan (ja******@hotma il.com) writes:
Somehow, '-n' doesn't work. It doesn't remove the "(# of rows
affected)" message from the end of the result. Actually, I don't
really know what '-n' is supposed to do. ISQL/OSQL output the same
thing regardless I use '-n' or not.


-n removes 1> 2> etc from the output.

To get rid ot "rows affected", use SET NOUCOUNT ON.

John's suggestion to use BCP sounds like a good approach.

--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #5
> -n removes 1> 2> etc from the output.

I believe this is what it is supposed to do. Strangely, that -n switch
doesn't do anything for me. The output always doesn't have 1> 2>...
regardless I use -n or not. Anyway, this is not where my problem is.
Therefore, I will not get too deep into this.
John's suggestion to use BCP sounds like a good approach.
All my other programs use ISQL. Therefore, I want to stick with the
"tried and sort-of-true". Thanks anyway.
To get rid ot "rows affected", use SET NOUCOUNT ON.


Good. This gets rid of the "rows affected" message. Turned out this
particular problem was caused by two factors:

1. Somewhere in my stored procedure, it restored SET NOCOUNT ON to
OFF. That was the reason why I could not remove that "rows affected"
message.

2. ISQL always outputs "rows affected" message regardless I use SET
NOCOUNT ON or not. OSQL doesn't have this problem. This means I should
use OSQL from now on.

With "rows affected" out of the way, the remaining problem is the
extra blank space in the beginning of each line in the output when I
replace PRINT statements with one SELECT statement.

I will contact the outside developer who is developing a program that
will import the output file from my stored procedure. If he is OK with
the extra blank space in front of each line in the output file, I will
not need to do anything other than changing the PRINT statements in my
stored procedure with one SELECT statements. And I will be done.

Thanks for the information.

Jay Chan
Jul 20 '05 #6

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

Similar topics

1
1490
by: Taki Jeden | last post by:
Hi I'm trying to figure out how to produce, in wxPython, a table/list/grid/whatever which would wrap long lines, and of course adjust row height. But I can't find any ready-made widget, nor any sensible solution. My recent idea is to use wxHtmlWindow to produce ordinary html table - I hope somebody here knows a better way to do that :) Bartek G.
2
13485
by: Bob | last post by:
Everybody, I've been doing a lot of on-line research and cannot find any reference to the exact problem I'm having. Let me preface this question with the fact that I'm coming from an Oracle background so my approach may not be the best way to tackle this. However, from the research I have done this approach seems reasonable. Also, I know about the undocumented procedure sp_MSforeachtable. That can give me a
1
3324
by: Alan Zhong | last post by:
hi, i had been removed the row counts and the column spaces... but i failed to remove the extra tabs between rows of data return from the osql output. how to detect the row delimiter? i noticed i can use bcp to have a more decent output file, but i don't want to do too much of file read-write. the programming enviroment is quite easy to "capture" the output from the comand prompt. secondary, char(252), 253, 254, 255 is not being read...
1
2829
by: Robizzle | last post by:
I'm writting a script that produces html source code from form input. My problem is that I want to format my html source with new lines and tabs. So, I have a string that holds all the contents of the source and my php script displays it by saying echo '<form><textarea>'.$sourcestring.'</textarea></html>'; All of that is working currectly except that I don't know how to get the tabs and new lines in the string.
1
11262
by: Philip Bondi | last post by:
Hello to all SQL Server junkies who work with non-English characters: For people running scripts from the command line using ANSI files with special characters, it is very important to use isql and disable "Automatic ANSI to OEM conversion": - This only affects isql from the command line, and no gui applications - http://support.microsoft.com/?scid=kb;EN-US;153449 - Start the "Client Network Utility" C:\WINDOWS\system32\cliconfg.exe
9
1654
by: julian_m | last post by:
given that php echo '<div>'; echo 'whatever'; echo '</div>'; echo '<div>'; echo 'whatever'; echo '</div>'; echo '<div>'; echo 'whatever'; echo '</div>';
1
1188
by: vps | last post by:
Do I need to break a mail message into lines of 70 characters each? Apache 2.2 with PHP 5.2.5 sends messages with lines of any length at my localhost with all characters intact. Thank you very much!
8
2221
by: Jonathan Sachs | last post by:
I'm trying to compose a list of items, each of which consists of text that wraps around a picture at the left margin. The examples I have seen tell me to do it like this: <p><img src="xxxx.jpg" align="left" width=nn height=nn>zzz zzzzz zz zzzzz...</p> In my case, since the wrapped text includes a headline, I assume I am supposed to do this:
2
5811
by: ncsthbell | last post by:
I am trying to construct a 'Copy' statement in Access 2000 vb that I will actually write out to create a .bat file. My problem is that I need to put quotes around the vcFileFrom and vcFileTo (“vcFileFrom” and “vcFileTo”) to be able to handle having spaces in the file name. I just can not seem to get the correct syntax in my access vb code to get the quotes around the filenames. I have the following code: OutRec = "Copy " & vcFileFrom & ",...
0
8403
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8833
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8737
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8610
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7345
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.