Solved

how do i save the xml created by query

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

[Webinar] Disaster Recovery and Cloud Management

Learn from Unigma and CloudBerry industry veterans which providers are best for certain use cases and how to lower cloud costs, how to grow your Managed Services practice in IaaS clouds, and how to utilize public cloud for Disaster Recovery

Question has a verified solution.

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

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.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

863 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

23 Experts available now in Live!

Get 1:1 Help Now