Solved

Why won't my results save to the xml path I specified in my stored procedure?

Posted on 2012-03-10
1
370 Views
Last Modified: 2012-04-12
Here is my code:

 EXEC master..xp_cmdshell
               'bcp "SELECT title
                                   ,author
                                   ,location
                                   ,ISBN
 FROM    libraryInventory
 WHERE  inventory_level > 2            
 for xml auto, elements, root(''location'')
               "
               queryout \\main\libraries\locations\inventories.xml -x'

Instead of outputting my result to the above path, this is what I get as a result:
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]
NULL
What am I doing wrong?
0
Comment
Question by:programmher
1 Comment
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 37705006
remove the newlines from your sql...

EXEC master..xp_cmdshell  'bcp "SELECT title ,author,location,ISBN FROM    libraryInventory WHERE  inventory_level > 2   for xml auto, elements, root(''location'') " queryout "\\main\libraries\locations\inventories.xml" -x' 

Open in new window


you might consider moving the query into a view, and just use the view name (as table name) instead, this will shorten this code.

you could build the "sql" into a variable, if it's about readability

declare @cmd varchar(1000)
set @cmd = 'bcp "SELECT title ,author,location,ISBN '
set @cmd = @cmd + ' FROM    libraryInventory WHERE  inventory_level > 2 '
set @cmd = @cmd + ' for xml auto, elements, root(''location'') " '
set @cmd = @cmd + ' queryout "\\main\libraries\locations\inventories.xml" -x' 
exec(@cmd)

Open in new window


hope this helps
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

705 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

18 Experts available now in Live!

Get 1:1 Help Now