We help IT Professionals succeed at work.

BCP QUERY OUT

steven
steven asked
on
88 Views
Last Modified: 2019-02-21
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
Comment
Watch Question

Database Consultant
CERTIFIED EXPERT
Top Expert 2009
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
stevendeveloper

Author

Commented:
Thank you very much!

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions