Link to home
Start Free TrialLog in
Avatar of Tom Sage
Tom SageFlag for United States of America

asked on

BCP export to Text file skips rows

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

ASKER CERTIFIED SOLUTION
Avatar of Andrew Crofts
Andrew Crofts
Flag of Ukraine image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Sage

ASKER

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.