Solved

how do i save the xml created by query

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

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

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
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

730 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