Avatar of steven
steven
Flag for United States of America asked on

BCP QUERY OUT

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
DatabasesXML

Avatar of undefined
Last Comment
steven

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Aneesh

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
steven

ASKER
Thank you very much!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy