Solved

export data

Posted on 2004-08-05
6
1,379 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
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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Question 3 49
DBF to ... Converter 5 83
Need help constructing a conditional update query 16 71
Need help in debugging a UDF results 7 29
I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
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…

820 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