Solved

export data

Posted on 2004-08-05
6
1,392 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
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…

630 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