Solved

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

Posted on 2012-03-10
1
380 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 143

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

630 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