Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how do i save the xml created by query

Posted on 2013-06-12
3
Medium Priority
?
303 Views
Last Modified: 2013-06-16
hi, i want to create an sitemap for search engines, so i have this code in place:

    WITH XMLNAMESPACES 
    (
        DEFAULT 'http://www.sitemaps.org/schemas/sitemap/0.9'
    )
    SELECT ('http://www.myurl.com/View.aspx?id=' + LTRIM(STR(t1.id))) AS 'loc'
    FROM    
        tb_table as t1 
    FOR XML PATH('url'), ROOT('urlset')

Open in new window


so my question is, i want after the query executed to save the xml file on harddrive, so after i executed i can put the xml sitemap on place to search engines read the file. And also, is this code above complete, is this the right way to create sitemaps for search engines based on database tables. do i have all paramters?
0
Comment
Question by:rafaelrgl
[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
3 Comments
 
LVL 22

Expert Comment

by:plusone3055
ID: 39241410
0
 
LVL 1

Author Comment

by:rafaelrgl
ID: 39242465
what's the command in sql to save this xml created by the query i post above. that's my goal
0
 
LVL 12

Accepted Solution

by:
Saurabh Bhadauria earned 2000 total points
ID: 39243948
You can use BCP or SQLCMD using xp_cmdshell   to achieve this...

for BCP .. get a example here
http://www.codeproject.com/Tips/239156/Export-data-from-SQL-Server-as-XML 

for SQLCMD ..

EXECUTE master..xp_cmdshell 'SqlCmd   -S SAURABHBHADURIA -d master  -E  -i d:\query.sql  -h -1 -y 0 -o d:\out.xml '

Open in new window


in d:\query.sql File I have save my query ..which is below..

 set nocount on
:XML ON
  SELECT top(50) name,type FROM master.sys.objects s for xml Raw ,elements , ROOT ('Export')


Thanks,
Saurabh
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

593 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