Solved

BCP export to Text file skips rows

Posted on 2009-07-06
2
330 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

947 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

19 Experts available now in Live!

Get 1:1 Help Now