Solved

BCP export to Text file skips rows

Posted on 2009-07-06
2
329 Views
Last Modified: 2012-05-07
Please look at the BCP statement below.  It does export data to a text file, but it skips some of the rows.  I know BCP is skipping rows because I compared the BCP output with the output from a .NET program using a DataReader where I exported one row at a time.  I would like to use BCP because it is faster.

Thanks for any ideas
ALTER Procedure [dbo].[BCP_to_Text]

(  

@table varchar(255),  

@FileName varchar(255)  

)  

as  

If exists(Select * from information_Schema.tables where table_name=@table)

    Begin

        Declare @str varchar(1000)  

        set @str='Exec Master..xp_Cmdshell ''bcp "Select * from '+db_name()+'..'+@table+'" queryout "'+@FileName+'" -T -c'''  

        Exec(@str)  

    end

else

    Select 'The table '+@table+' does not exist in the database'

Open in new window

0
Comment
Question by:MisterT25
2 Comments
 
LVL 13

Accepted Solution

by:
Philip Pinnell earned 500 total points
ID: 24792208
If you run bcp Select * from table queryout fileName -T -c
 manually from the command prompt do you get the same results and does it have as many records as running Select * from table in query analyser ?


0
 

Author Closing Comment

by:MisterT25
ID: 31600419
Thank you for your feedback.  I have decided not to use bcp since I do not have enough time to resolve this problem.  Closing this case.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now