Solved

how do i save the xml created by query

Posted on 2013-06-12
3
299 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 500 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

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.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

724 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