Solved

how do i save the xml created by query

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
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.

707 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

16 Experts available now in Live!

Get 1:1 Help Now