OSQL Output File Garbage

Jul 20, 2005

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
result similar to what I'm looking for but the format of the
output is not what I need.

Now the problem. I'm trying to write a reusable script to give
me a list of all the tables in a database that have 1 or more rows.
My approach is to a BAT file (see script 1 below) that calls OSQL
twice, once to call a SQL script (see script 2 below) that uses the
Information_Schema views to generate the SELECT COUNT(*) statements
and fill in all the tables names in the database, write this to a
temporary output file and the second OSQL command to read the
temporary output file and generate me the results formatted the
way I need.

The result of the first OSQL run is correct EXCEPT for 1> 2> 3> 4> 5>
6> 7> 8> 9> 10> 11> 12> 13> garbage at the beginning of the file.
Because of this garbage the 2nd OSQL command blows up! Anyone have
any idea what is generating this garbage?

If I manually edit out the garbage and then just run the 2nd OSQL
command
I get similar garbage in the final result file (see 2nd result file
below).

In Query Analyzer, when I run the GET_TABLE_COUNT.SQL Script manually
then take its output and copy and paste it to a new query window and
run that it works OK except for generating lots of blank lines where
the result of the tables that have zero rows are. I am suppressing
headings but am still getting the blank lines but at least it works!

Any ideas anybody? Thanks For Any Help
FYI -- SQL Server 2000 with SP3a.
Bob

================== Script 1 - BAT File to Call OSQL ===============

@echo off
@echo ************************************************** *************
@echo .
@echo get_table_count.bat
@echo .
@echo Before you run this script change to the drive and directory
@echo where the input SQL script is located!
@echo .
@echo Input parameters:
@echo 1) SQL Server userid
@echo .
@echo You will be prompted twice for your password!
@echo .
@echo The output is written to file TABLE_COUNT_RESULT.TXT
@echo .
@echo ************************************************** *************
pause
osql -U %1 -S devkc-db -d C3T_Architecture -i get_table_count.sql -o
temp_table_count_query.txt -h-1 -w500
osql -U %1 -S devkc-db -d C3T_Architecture -i
temp_table_count_query.txt -o table_count_result.txt -h-1 -w500
del temp_table_count_result.txt
@echo on

================================================== ====================

================ Script 2 - GET_TABLE_COUNT.SQL Script ===============

set nocount on
select 'set nocount on'
select 'select ''Table Name Count'''
select 'select ''========== ====='''
select 'select '''
+ table_name
+ ''', count(*) from '
+ table_name
+ ' having count(*) > 0 '
from information_schema.tables
where table_type = 'BASE TABLE'
order by table_name

================================================== ====================


============ Partial Result of 1st OSQL Run ==========================

1> 2> 3> 4> 5> 6> 7> 8> 9> 10> 11> 12> 13> set nocount on

select 'Table Name Count'

select '========== ====='

select 'ACT_ASSERTION_RULE', count(*) from ACT_ASSERTION_RULE having
count(*) > 0
select 'ACT_ASSOC', count(*) from ACT_ASSOC having count(*) > 0
select 'ACT_DOC', count(*) from ACT_DOC having count(*) > 0

================================================== ====================


============ Partial Result of @nd OSQL Run ==========================

1> 2> 3> 4> ... I edited out the intervening numbers for this message
.... 664> 665> 666> 667> Table Name Count

========== =====

.... I edited out lots of blank lines in the result for this message
before I get to the first table with 1 or more rows ...

ARCH 6

================================================== ====================

View 2 Replies


ADVERTISEMENT

OSQL Query Output

Dec 10, 2007

Hi All,

The command showed below provides the output shown:

set @cmd = 'osql -S bcgsql1cgsqldev -U checkdb -P checkdb -q "set nocount on; select errorlogdesc from ##errors where datediff(dd,errorlogdatetime,getdate()) = 1 and errorlogdesc like ''%Error:%''" -h-1 -w 900 -o J:ScriptsTestStuffErrorLogMsg.txt'


Here is the output:

Error: 17883, Severity: 1, State: 0




Error: 17883, Severity: 1, State: 0


I need to remove the space between the two lines so I set the -w parameter to 900 but that didn't fix it. Any idea how I can accomplish this?

Thanks

View 4 Replies View Related

Row Delimiter From Osql Output

Jul 20, 2005

hi, i had been removed the row counts and the column spaces... but ifailed to remove the extra tabs between rows of data return from theosql output.how to detect the row delimiter?i noticed i can use bcp to have a more decent output file, but i don'twant to do too much of file read-write. the programming enviroment isquite easy to "capture" the output from the comand prompt.secondary, char(252), 253, 254, 255 is not being read by the commandprompt, for example, 253 turns into 132 when i decode the input.thankx.from alan.

View 1 Replies View Related

Using OSQL For Query Output (csv Formatted)

Jun 12, 2006

I'm running a query with osql, and I'm trying to get some clean output that is comma delimited. So far my line looks like this:osql -E -n -d mydb -i custom.qry -o "c:output
esults.csv" -h-1 -s ","This works off a table with only two columns. I'm still left with a lot of extra spaces between the first column output and second column output, and at the bottom the text "(50 rows affected)".So instead of this:data1a (lots of spaces here) ,data1bdata2a (lots of spaces here) ,data2bdata3a (lots of spaces here) ,data3b(50 rows affected)I want to see this:data1a,data1bdata2a,data2bdata3a,data3bThanks very much for any help. :)

View 2 Replies View Related

ISQL And OSQL Output Lines Wrapped Around At 256 Characters?

Jul 20, 2005

I am trying to use a command line program to run a stored procedurethat generates output in a comma-delimitted format. Somehow, ISQL orOSQL always wrap the lines at 256 characters. I believe this hassomething to do with the column width switch (-w). But enlarging thecolumn width to 800 characters max still doesn't help. The followingis a stored procedure that is essentially doing what my storedprocedure is doing:create procedure MyTest asset ansi_padding onset nocount ondeclare @sTest varchar(300)-- Output three lines. Each line has 259 characters.select @sTest = "1234 6789 ... 1234 6789"print @sTestselect @sTest = "1 3 5 7 9 ... 1 3 5 7 9"print @sTestselect @sTest = "1 3 5 7 9 ... 1 3 5 7 9"print @sTestset nocount offreturn( 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.txtBut they have the same problem. The output lines all wrap around at256 characters.Strangely, if I store the result in a temporary table, and then useSELECT to output the result from the temporary table, I will not havethat problem. Seem like the "-w" switch only works for output fromtables, but not for output coming from PRINT. Unfortunately, usingthis approach has another set of problems (one blank space in front ofeach line, "number-of-rows affected" shows up at the bottom).Therefore, I would like to stick with using PRINT statements to outputthe result.Please suggest a way to fix this line-wrapping-around problem.Thanks.Jay Chan

View 5 Replies View Related

OSQL -- Print Into File

Sep 4, 2003

Why osql igores parameter -w for command PRINT... and why cut the last character ????

osql -S<Server> -d<DB> -E -Q"Print replicate('ab',250)" -otest.txt -n -h -b -w1000

this one example returns two rows, first has 255 characters and second only 244 characters...

View 3 Replies View Related

OSQL Batch File Problem

Aug 22, 2006

I have a scheduled task that runs a batch file in windows 2003 server which
is running SQL Server 2000 Enterprise.

The batch file contains the line:

OSQL -i myscript.sql -Umyuser -Pmypassword -Slocalhost -o mytrans.log

the 'myscript.sql' file updates a table with another table of the exact
number of rows.

When the scheduled task runs, the 'mytrans.log' file shows 0 rows were
affected.

If I run this myself from the command line, 22,000 rows are affected which
is correct.

I am guessing there is some sort of permission/authentication issue here. I
am sending the right username/password for SQL and for windows to run the
task.

Any idea what I could do to fix this?

Thanks,

Nitrox

View 1 Replies View Related

Executing Osql Commands Through Batch File

Sep 13, 2006

Hello

I have a script ,which runs with osql

The script is :

osql -E
declare @cmd nvarchar(1000)
declare @cmd2 nvarchar(1000)
declare @state1 varchar(100)
declare @message varchar(100)
set @message = ''
-- Build command to determine state of SQLSERVERAGENT service on Master Server
SET @CMD = 'create table #state (state varchar(2000))' + char(10) +
'declare @cmdx varchar(1000)' + char(10) +
'insert into #state EXEC master..xp_servicecontrol ''''QueryState'''', ''''SQLSERVERAGENT''''' +
+ char(10) + 'select @state=state from #state' + char(10) +
'drop table #state'
-- Build command to execute command that determines state of service being monitored
set @cmd2 = 'declare @state varchar(100)' + char(10) +
'exec ' + rtrim(@@servername) + '.master.dbo.sp_executesql N''' + @CMD + ''',' +
'N''@state varchar(100) out'',' +
'@state out' + char(10) +
'set @state1 = @state'
-- Execute command and return state of service being monitored
exec master.dbo.sp_executesql @cmd2,N'@state1 varchar(100) out',@state1 out
-- Is the service that was monitored not
IF (UPPER(@state1) <> 'RUNNING.')
--if @state1 <1 'Running.'
begin
-- Display message that primary monitor is down
select @message = @message+char(13)+ @@servername + ' -' + 'Sql Server Agent Not Running'+char(13)
print 'Master server "' + rtrim(@@servername) + '" for monitoring is not available.'
exec master.dbo.xp_smtp_sendmail

It works fine when I run it on the command line prompt.
And I receive a mail , if the server agent is running.

But when I save it as bat file and try to run , it stops and doesnot even give an error.

Can anyone let me know what I can do.

Thanks

View 1 Replies View Related

Formatting Question With Osql Batch File

Jul 23, 2005

Hi all,This is my first batch file and I want to query a database and outputit in a textfile. Up to now that works, the only problem is theformatting in the text file. It's all screewed up...lines aren't linedup and columns aren't right....how do you format the result from aquery to a text file. Here's my code:osql.exe -S MYMACHINE -w 30 -E -d Demo2 -Q "select * from Title wherefrequency = 'monthly'" -o "C:output.txt"Thanks....JMT

View 1 Replies View Related

How To Apply A Sql Script File On Sql Server 2000 Without OSql.exe

Mar 5, 2007

Hi guys
I need to apply a sql script file on Sql server 2000 by .net 2.0 program. but on the current running machine, there is not Osql.exe file. Do you guys know how to execute the sql file without the command? Is there any way provided in .net library ?
Thanks for you response!

View 3 Replies View Related

Running A SQL File From OSQL Command Line Utility

Jul 20, 2005

Hi,I have dumped a very large database from mysql (using mysqldump program)as a raw sql file. The reason was, convert this database to a MSSQLdatabase. Since mysqldump creates the file as raw sql file with thedatabase-table structures and the data in it, I thought using OSQL commandline utilities should work to out this whole database in MSSQL server.I have run this command from command line:osql -u sa -i mysqldump.sqlIt is going since yesterday. It has been almost 36 hours that it'sstarted. And in the mssql server, I see no database created yet. On thescreen of the command line, I see bunch of numbers are going in order. Iassume they are row numbers of the tables processed. But, if it is doing it,then where is it saving all this data ? I have checked the tempdb, pub db,other dbs, and I see no tables related to the database I am inserting. Willit populate it at the and of the job ? Or, am I doing something wrong here?Regards.Murtix.

View 2 Replies View Related

DOS Batch File Running Osql - Opening/closing Connections

Jul 20, 2007

I've written a small dos batch script that runs a simple query throughosql and then calls an exe which sends an email if the returned value


Quote:

View 2 Replies View Related

Some Problems With Garbage Collection

Jul 3, 2004

hi evryone
I have a question!
in my ASP.NET page I use a SqlDataAdapter object for working on my database
first I declare it as a global vaiable(SqlDataAdapter objDataAdapter;)
then I construct it in my Page_Load procedure like this
(objDataAdapter=new SqlDataAdapter(strSql,objConnention))
then when I want to use it in my other procedures an error tells me that your object does not exist
for solving this error I should construct my objDataAdapter in evry procedure using it.
but I think such variables should not be erased from Heap automatically(with Garbage Collection)
because it has a reference to Stack. I mean the global variable...
any opinion ?
Thanks

View 3 Replies View Related

Garbage Query Displaying

Sep 10, 1999

Hi all!
I´m getting a very unpleasant result when I use "SELECT * FROM <many-columns-table (40+)>". Each query row appears with overwritten columns (not all but some of them)... also outside EM window !!!
There is no data corruption on EM nor Windows, all programs remains running with no other sign but garbage overwritten... garbage dissapears after window refreshing.
Just 1 month ago I made a 2-day full reinstall of my computer, so I don´t know what program could install an offending module/DLL/??? buy I´m sure it was working before. I hate that!
Have you ever noticed something like that?
Do you think is a DLL problem?
Do you know a turn around? (I don´t want to reinstall all again!!!)
Actually I´ve tried reinstalling SP4, SP5 on WS, uninstalling/reinstalling Client with no luck...
Thanks,
Cesar.

View 1 Replies View Related

Garbage In Sql Server Log Files

Mar 4, 2004

hi,
My database server had hung up recently, and I had to restart it.
After checking the log I found some garbage entries in it.
has anyone encountered similar errors?
harshal.

View 5 Replies View Related

Flatfiles With Garbage Data

Nov 13, 2006

I was testing my packages today and my packages were running sucessfully when I didnt have any valid data in the flat file. One the reason was as not rows were returned from the flat file none of the validation script components returned any err.

How do I count the # of rows which were read from flat file from the package and continue only if there is more than one row.

I tried using conditional split but as I wont have the row count value availble till the dataflow task runs this didnt help.

Is it best for me to have two dataflow tasks one resturns the count of records from flat file and the other starts if there are any rows. Now my problem is if I have rows to process how to I transfer the flatfile data to validate from DataFlowTask1 to DataFlowTask2?

I have a script task whcih counts the rows and decides to the TaskResult but once the TaskResult is sucess how do I use the values read in DataFlowTask1?



Appreciate ur help in advance

View 9 Replies View Related

Atlernative To SQL Server Management Studio (i.e. Garbage) . Any Suggestions?

Oct 26, 2007

Folks I have recently had the misfortune of moving to SQL Server Managment Studio as per our upgrade to SQL 2005. There is no doubt that SQL Server Management is a major disappoinment compared to Enterprise manager.
The UI is the biggest disaster I have ever seen. Getting rid of the SQL Query analyzer tool was a TERRIBLE idea. The UI is buggy and unfriendly. It is a major POS. I hope someone in the SQL Dev team is listening / reading this post (hellooooo anybody homeee......)
 Now that I have vented my frustration ...
 I wanted to know any atlernatives to the SQL Server Management Studio. There are plenty of 3rd Party tools out there I wanted to find out from this forum which popular 3rd Party tools are most developers using
 Thanks for bearing with me.
 

View 7 Replies View Related

Deploy To Production Server / SSIS Writes Out Garbage Data

Apr 2, 2015

I built a SSIS(writing out to a flat file ) in 32 bit machine and it woks fine . But however when I deploy to the produciton server(64 bit) the SSIS writes out garbage data . After some research I found out that the problem with the 32 bit OS and 64 bit OS problem.What is my next step. Am I out of luck that now I will have to redesing the SSIS in 64 bit?

View 5 Replies View Related

Generate A Separate Txt File For Each Account In A Table, Need To Join Tables To Get Details, And Specify Output File Name?

May 16, 2008

Hey,



I'm looking for a good way to rewrite my T-SQL code with 'bcp' to SSIS package, any help would be greatly appreciated?



I have table1 contain account numbers and output-filename for each account,

I need to join table2 and table3 to get data for each account in table1, and then export as a txt file.



Here is my code using bcp (bulk copy)

DECLARE @RowCnt int,
@TotalRows int,
@AccountNumber char(11),
@sql varchar(8000),
@date char(10),
@ArchPath varchar(500)

SET @RowCnt = 1
SET @date = CONVERT(CHAR(10),GETDATE(),110)
SET @ArchPath = '\D$EDATAWorkFoldersSendSendData'
SELECT @TotalRows = count(*) FROM table1
--select @ArchPath

WHILE (@RowCnt <= @TotalRows)
BEGIN
SELECT @AccountNumber = AccountNumber, @output_filename FROM table1 WHERE Identity_Number = @RowCnt
--PRINT @AccountNumber --test
SELECT @sql = N'bcp "SELECT h.HeaderText, d.RECORD FROM table2 d INNER JOIN table3 h ON d.HeaderID = h.HeaderID WHERE d.ccountNumber = '''
+ @AccountNumber+'''" queryout "'+@ArchPath+ @output_filename + '.txt" -T -c'
--PRINT @sql
EXEC master..xp_cmdshell @sql
SELECT @RowCnt = @RowCnt + 1
END

View 7 Replies View Related

File System Task - Output File Variable Syntax????

Feb 7, 2007



Hi

This should be incredibly simple and easy, but I can't find any examples of how to do this.

I just want to make a File System Task move a file, and have the destination be filename + date and time. For example \serversharefilename02072007.txt

What syntax do I use in a variable to make this work?

Thanks

View 16 Replies View Related

Transact SQL :: Output A File With A File Header

Aug 27, 2015

In my SSIS Package, I have to write my [FileHeaderRecord] row, then my [BatchHeaderRecord] row, then my details. How can I do this in a SQL Server Query? When I try my SSIS, my file looks like so..

FHTEST 00000208262015             BH000208262015  

I want my BH, Batch Header data, to appear on a new row in the file.Do I have to build a dynamic query to do this?Is there any trick in SSIS to do something like this?I did try creating separate Data Flow Tasks to Query the [FileHeaderRecord] and then use a Flat File Destination and then another Data Flow Task to Query the [BatchHeaderRecord] and use a Flat File Destination again NOT overwriting the file.

View 2 Replies View Related

Output Column Width Not Refected In The Flat File That Is Created Using A Flat File Destination?

May 11, 2006

I am transferring data from an OLEDB source to a Flat File Destination and I want the column width for all of the output columns to 30 (max width amongst the columns selected), but that is not refected in the Fixed Width Flat File that got created. The outputcolumnwidth seems to be the same as the inputcolumnwidth. Is there any other setting that I am possibly missing or is this a possible defect?

Any inputs will be appreciated.

M.Shah

View 3 Replies View Related

SQL 2012 :: Creating Dynamic SSIS File Format - Dynamic CSV File As Output

Mar 2, 2014

I am trying to create an ssis package with dynamic csv file as output. and out format contains query output.

sample file name:

Unique identifier + query output + systemdate();

The expression is looking like this.

@[User::FilePath] + @[User::FileName] + ".CSV"

-- user filepath is a variable from ssis package. File name is the output from SQL query. using script task i have assigned the values to @[User::FileName] .

When I debugged the script task the value getting properly but same variable am using for Flafile destination. but its not working.

View 3 Replies View Related

Output File

May 29, 2001

Hi all!
My question is quite simple I think... I am directing the result of my query to an output file my problem is how to set the rowsize of my output file to more than 256 (that is the default maximum)? My query result is quite long per row (assuming one column) in query anlyzer, I can easily adjust the result to more than 256 but the result in the output file is truncated because the ouput is more than 256 characters per row...how can I set (in the code) the length of the row of the result in the output file... thanks for the help... this is quite urgent...

Lhot

View 3 Replies View Related

Output File

Nov 16, 2006

venkatesh writes "Hi all,

I have a simple sql Query, when I execute the query the result should also be written to a text file. Can I do that in SQL 2000?

Thanks
-Venky"

View 3 Replies View Related

SP Output Into A File

Jul 13, 2007

I have SQLServer7. I am running some stored procedure. I would like to know how I can redirect the output of the Stored_procedure run into a file?



R

View 8 Replies View Related

Need Help With XML Output To File

Sep 18, 2007

I'm using SQL Server 2005 / 9.0.3042

I'm not new to sql server, but making my first experience with xml in sql server 2005.


I have a query like this (based on <Table> with neccessary data):

SELECT TAG, PARENT, <columns...>
FROM <Table>
FOR XML EXPLICIT

This query creates a xml file exactly as i need it when i execute it in Management Studio. Well, with one exception. It does not write the <xml...> tag at the beginning of the xml file. But i'm sure i get that in there somewho else. What i need to do now is get that output to a file on disk. And that's where my problem starts.

I tried SQLCMD within Management Studio, but that doesn't accept the ':XML ON' tag and ignores it. the resulting file written is not usable, as it also contains query summary information.

Any direction would be greatly appreciated!

View 4 Replies View Related

Output To A File

Jul 18, 2007

Hi, All

I have a header row and a footer row and a bunch of detail data I have managed to split up into temp db tables, know i need to know what would I need to do to write the header , detail data and footer to the same file after all my validations have completed , this would be a different file then the one I originally imported all the data from (append to text delimited file).
Idealy I would only like to change the header and footer from the original file.

Any ideas - I am thinking of writing a application that does this for me and just executing it from
SSIS but I would really like to stick with standard SSIS components first before starting to write my own stuff.

Thanx in advance
Rudolf Erasmus

View 5 Replies View Related

EDI File Output

Oct 2, 2007

any good example of extracting data from sql server 2005 in EDI file format? I need to generate EDI files from sql server

thanks

View 1 Replies View Related

Output To A Text File

Sep 3, 2006

Is it possible to send the output of a query to a text file in a stored procedure? When I run stored procedure in Query Analyzer I am able to do that and I am wondering if this is possible in a automated way?

View 2 Replies View Related

Output In The File, Help Needed

Jun 11, 2001

Hi,
Is it the way use T-SQL to select text data from table and add them to the file on a HD, but save the information in the file without changes anything that was in the file before, another words without rewriting, just add?

Help needed - urgent!
Thanks beforhand.
Dmitri

View 2 Replies View Related

Output Query To A File

Jul 25, 2001

I have a query something like this:
select "bcp EISAT_08_18.."+name +" OUT C:"+ name+".TXT -c -t -SCJACOBI"
from sysobjects
where type = 'U'
ORDER BY NAME
When I run the above query I want to output the result of the query to a file.
Can someone help me on that?

View 8 Replies View Related

Output The Query Into A File

Jul 31, 2001

Hi all,
When I run a query in the sql query analyzer I need to write the output of that query in to another file. In Oracle its spool. Can someone help me on this please. Thank you!!!

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved