troubleshooting Question

BCP QUERY OUT

Avatar of steven
stevenFlag for United States of America asked on
DatabasesXML
2 Comments1 Solution96 ViewsLast Modified:
BCP QUERY OUT, I am not sure how to query out, so i am attempting to output the headers which i will then combine with the data. I have never used query out to do this as we usually create a table and place the headers in the bcp the data out of the table then combine.   IS it possible to do this with query out..

                                                declare @outfile nvarchar(1000),@comrun nvarchar(500)
                        set @outfile = '\\eincutil01\Syteline\report\outputfiles\ezimmerman\'  + db_name() + 'PaperLessBak.csv'


                     SET @HEAD = 'BCP "select ''CONUM'',''LINE'',''CUSTPO'',''BILLTO'',''BILLTOADDR'',''SHIPTO'',''SHIPTOADDR'',''SHIPCODE'',''DESCTIPTION'',''ITEM'',
                                   ''DESCRIPTION'',''UM'',''QTYORDER'',''QTYREQUIRED'',''QTYSHIPPED'',''WHSE'',''DUEDATE'',''PROMISEDATE'',''CERTYPE'',''COFC'',''COLLECTACCT'',
                                   ''LOCATION'',''QTYONHAND'',''ITEMTOBECUT'',''ITEMTOCUTTO'',''QTYTOCUT'',''LOC'' " queryout ' +  @outfile +'  -c -t, -T -SEINCDATA01'
                                       PRINT  @HEAD
                        
                              exec master..xp_cmdshell @HEAD
                        
                              exec master..xp_cmdshell @HEAD

ERROR
usage: BCP {dbtable | query} {in | out | queryout | format} datafile
  [-m maxerrors]            [-f formatfile]          [-e errfile]
  [-F firstrow]             [-L lastrow]             [-b batchsize]
  [-n native type]          [-c character type]      [-w wide character type]
  [-N keep non-text native] [-V file format version] [-q quoted identifier]
  [-C code page specifier]  [-t field terminator]    [-r row terminator]
  [-i inputfile]            [-o outfile]             [-a packetsize]
  [-S server name]          [-U username]            [-P password]
  [-T trusted connection]   [-v version]             [-R regional enable]
  [-k keep null values]     [-E keep identity values]
  [-h "load hints"]         [-x generate xml format file]
  [-d database name]        [-K application intent]
NULL
ASKER CERTIFIED SOLUTION
Aneesh
Database Consultant
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros