• subscribe
July 24, 2002 12:00 AM

Tip: Beware of Using the QUERYOUT Option with Command-Line Bcp

SQL Server Pro
InstantDoc ID #25631

Bulk copy program (bcp) lets you copy data out of SQL Server based on the result set of a query that's specified on the bcp command line. The Q&A "Does the SQL Server 7.0 version of bulk copy program (bcp) let you create an output file from a query without having a VIEW to put the result set in?" August 1999, InstantDoc ID 5867, explains how you can use the QUERYOUT option to accomplish this kind of data copying. But a SQL Server Magazine reader recently told me about a bug in bcp that forces the query specified in QUERYOUT to execute twice. (For a full description of this bug, see the Microsoft article "BUG: Bcp.exe Executes Query Twice When QueryOut Argument Used" at http://support.microsoft.com/search/preview.aspx?scid=kb;en-us;q309555.)

Of course, executing a query twice is inefficient, especially when you're dealing with large data sets. You can still selectively bcp out data by defining a view in SQL Server that encapsulates the query you'd otherwise specify with the QUERYOUT option. You'll get the same output data set, but the query won't run twice.



ARTICLE TOOLS

Comments
  • Anonymous User
    7 years ago
    Jul 07, 2005

    This really helped me. Thanks a lot.

  • Anonymous User
    7 years ago
    Jan 12, 2005

    Helped solve a longstanding problem

You must log on before posting a comment.

Are you a new visitor? Register Here
  • SP1?
    I know there is a SP1 for SQL 2008 R2 available....and there is a "feature pack" as well... ...
  • SQL database mirroring
    I have SQL Server 2008 R2 Enterprise 64bit on Windows 2008 R2 Enterprise 64bit.  Each SQL Server has...
  • Dell Compellent Disk Drive
    Does anybody has experience with Dell Compellent Disk Drive? Basically, this system manages all disk...
  • Sql server performance tuning
    I need to find a tool that help me to optimize sql server,queries,improve the performance and solve ...