all groups > sql server programming > march 2004 >
You're in the

sql server programming

group:

OSQL


OSQL Anand
3/7/2004 11:04:44 PM
sql server programming:
Hi All,

I have written an batch file that is use to take a backup
of the existing procedure from the database and stores in
the undo\sprocs\ directory.

Code:

FOR /F %%1 IN (runsprocs) DO IF NOT EXIST ..\Undo\sprocs\%
%1.sql ECHO Undo\sprocs\%%1...>> %LOG% && ECHO
Undo\sprocs\%%1... && OSQL -S myserver -U sa -P sa -d
mydatabase -l 300 -b -n -h-1 -w300 -Q"PRINT 'IF EXISTS
(SELECT * FROM sysobjects WHERE type=''P'' AND name=''%%
1'') DROP PROC %%1 ' + CHAR(13) + CHAR(10) + 'GO' IF
EXISTS (SELECT * FROM sysobjects WHERE type='P' AND
name='%%1') EXEC sp_helptext %%1" -o ..\Undo\sprocs\%%
1.sql >> %LOG% & IF ERRORLEVEL 1 GOTO INSTALL_ERROR


Problem:

In here runsprocs.sql is a file it contains the list of
stored procedures.

Example:
sptest

It is working fine. But the problem is when it creates a
sql file in the undo directory the sql file contains
extra line breaks ?

How can i avoid the extra line breaks ? Can anyone help
me?

With Regards,
Re: OSQL Anand
3/8/2004 1:37:52 AM
Hi,

Expected Result:

IF EXISTS (SELECT * FROM sysobjects WHERE type='P' AND
name='sptest') DROP PROC sptest
GO

CREATE PROCEDURE sptest
AS

/*********************************************************
**************************
**
** Name: sptest.sql
**
** Description: This procedure is the Transaction for
Contract payment
** type.


Actual Result:

IF EXISTS (SELECT * FROM sysobjects WHERE type='P' AND
name='sptest') DROP PROC sptest
GO






CREATE PROCEDURE sptest




AS











/********************************************************
***************************



**





** Name: sptest.sql




**





** Description: This procedure is the Transaction for
Contract payment



** type.


In the actual result you can find lots of line breaks.
How can i avoid these extra line breaks/ empty spaces ?

With Regards,
Anand


[quoted text, click to view]
Re: OSQL Jacco Schalkwijk
3/8/2004 9:19:33 AM
Hi Anand,

Can you post the exact output that you get in your file? It isn't clear to
me where you get the extra line breaks.

--
Jacco Schalkwijk
SQL Server MVP


[quoted text, click to view]

Re: OSQL Jacco Schalkwijk
3/8/2004 9:31:16 PM
Hi Anand,

It seems like there is nothing you can do about it, because osql pads
(n)varchars with spaces. sp_helptext returns a result set with one row for
each line and a column of nvarchar(255), and the spaces with which the
column is padded cause the extra lines in your result. It seems that values
for the -w switch over 80 do not have any effect, i.e. the maximum length
for a line that is created is 80.

You can get a slightly better result by getting the stored procedure
definition from the information_schema.routines view:
osql -E -dNorthwind -n -h-1 -w80 -Q"SELECT routine_definition from
information_schema.routines where routine_name = 'custorderhist'"

This will give you the stored procedure text in one piece, but you have a
lot of spaces, up to 4000, at the end. And stored procedures that consist of
more than 4000 characters will not be output properly.


--
Jacco Schalkwijk
SQL Server MVP

[quoted text, click to view]

AddThis Social Bookmark Button