Solved

export data

Posted on 2004-08-05
6
1,389 Views
Last Modified: 2008-02-01
I need to export data from sql server on a daily basis , getting only new data

Im using master..xp_cmdshell 'osql -E -q "select * from pubs.dbo.authors" -o c:\test.txt'

However I want each row to be on its own line.. And right now I am getting a bunch of blank lines a wrapping.

Any ideas!!

Thanks!
0
Comment
Question by:TEALTEAL
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 4

Expert Comment

by:andertst
ID: 11729460
When you say wrapping, if you open the datafile with Notepad or some text editor, does it wrap less if you widen your window?

In Oracle, there is a set linesize command and I would guess the SQL*Server version of that command would be one place to look.

Stephen
0
 

Author Comment

by:TEALTEAL
ID: 11729611
No it wraps the same if I widen my window...thanks
0
 
LVL 17

Expert Comment

by:BillAn1
ID: 11730011
osql writes ot a text file, but the max colwidth is 80 chars. It is not really the best way to export data.
You would be much better off using a DTS package to export the data to a file
There you can specify headers, column seperators, line break characters etc
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 50

Expert Comment

by:Lowfatspread
ID: 11730647
try the -w parameter ,

and you can get headders , etc with osql

osql
    [-?] |
    [-L] |
    [
        {
            {-U login_id [-P password]}
            | –E
        }
        [-S server_name[\instance_name]] [-H wksta_name] [-d db_name]
        [-l time_out] [-t time_out] [-h headers]
        [-s col_separator] [-w column_width] [-a packet_size]
        [-e] [-I] [-D data_source_name]
        [-c cmd_end] [-q "query"] [-Q "query"]
        [-n] [-m error_level] [-r {0 | 1}]
        [-i input_file] [-o output_file] [-p]
        [-b] [-u] [-R] [-O] [-X[1]]
    ]

0
 
LVL 17

Expert Comment

by:BillAn1
ID: 11731393
The maximum you can set with -w is 80 , in this case I think this is not enough, hence the wrapped text.
0
 
LVL 9

Accepted Solution

by:
crescendo earned 250 total points
ID: 11731516
You need to set the width of the console before you run OSQL. You do this with the MODE command:

    MODE CON COLS=132

Then you can use the -w parameter on OSQL to set the width. However, this only applies to each session, and so if you run xp_cmdshell twice, once to set the width, once to do the export, you will lose the width setting when the export runs. Therefore, create a batch file and run that, with MODE... as the first line, and OSQL ... as the second.

A better way to do the export is to use BCP, which is happy to do wide rows. Try

    xp_cmdshell('BCP pubs.dbo.authors out C:\test.txt -w -T')

It will give you a tab-separated row, with CRLF at the end of each row, just right for import into Excel etc.
0

Featured Post

Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question