Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 using sqlcmd to export data from a table

Author  Topic 

Dilan13
Starting Member

6 Posts

Posted - 2010-08-26 : 15:45:59
I have a batch file which exports all data from the table to a text file. I initially used bcp which will create a file around 4MEG, but i had to switch to sqlcmd( since Bcp will not be available in the prod environment) and the output file is now around 17 MEG( eventhough the total number of rows are the same). Trying to understand why the size if so different and if it's possible to reduce the size of teh file anyway

using bcp

bcp %SQLDBDATA%..vw_BeamExport out %Dir%\CSBudgetExport\BeamOutput_Export_%cur_yyyy%_%cur_mm%_%cur_dd%_%cur_hh%_%cur_nn%_%cur_ss%.txt -S%SQLSERVER% -U"%SQLLOGIN%" -P"%SQLPWD%" -c
:EOF


sqlcmd -U"%SQLLOGIN%" -P"%SQLPWD%" -S"%SQLSERVER%" -d"%SQLDBDATA%" -Q"SELECT * from dbo.vw_BeamExport" -o "%Dir%\CSBudgetExport\BeamOutput_Export_%cur_yyyy%_%cur_mm%_%cur_dd%_%cur_hh%_%cur_nn%_%cur_ss%.txt" -s","
GOTO :EOF



tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-26 : 16:12:39
The size is so different because of the white space. Open both of the files to see what I mean.

Why won't bcp be available in production? Bcp is a client tool. It does not need to be installed on the production database server.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -