Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 28th, 2006, 07:02 AM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default scheduled export to XML file from sql 2005

I have a select statement FOR XML EXPLICIT which extracts information from a SQL2005 database table. The statement looks like this:
SELECT
       1 AS TAG
      ,NULL AS PARENT
      ,'http://www.xxx.com/ASR/CR/PHONE' [CRP:PHONE_STATISTICS_TABLE!1!xmlns:CRP]
      ,'http://www.w3.org/2001/XMLSchema-instance' [CRP:PHONE_STATISTICS_TABLE!1!xmlns:xsi]
      ,'http://www.xxx.com/ASR/CR/PHONE PHONE_STATISTICS.xsd' [CRP:PHONE_STATISTICS_TABLE!1!xsi:schemaLocation]
      ,VendorID + '_PHONE_' + substring ((convert(varchar(100),activity_date, 121)), 1, 10) AS [CRP:PHONE_STATISTICS_TABLE!1!FILE_NAME!element]
      ,COUNT(*) AS [CRP:PHONE_STATISTICS_TABLE!1!RECORD_COUNT!element]
      ,VendorID AS [CRP:PHONE_STATISTICS_TABLE!1!VENDOR_CODE!element]
      ,REPLACE(cast(Activity_Date as varchar(100)),'T00:00:00','T12:00:00') AS [CRP:PHONE_STATISTICS_TABLE!1!ACTIVITY_DATE!element]

,NULL AS [CRP:PHONE_STATISTICS!2!RECORD_NUMBER!element]
FROM tbl_xml_report

WHERE activity_date= (select CAST(FLOOR(@mydate) AS datetime))
GROUP BY [VendorID],Activity_Date

UNION ALL

SELECT
      2 AS TAG
      ,1 AS PARENT
      ,NULL --CRP:PHONE_STATISTICS_TABLE attribute xmlns:CRP
      ,NULL --CRP:PHONE_STATISTICS_TABLE attribute xmlns:xsi
      ,NULL --CRP:PHONE_STATISTICS_TABLE attribute xsi:SchemaLocation
      ,NULL --CRP:PHONE_STATISTICS_TABLE element file_name
      ,NULL --CRP:PHONE_STATISTICS_TABLE element record_count
,VendorID
,Activity_Date
,RECORD_NUMBER
FROM tbl_xml_REPORT
WHERE activity_date= (select CAST(FLOOR(@mydate) AS datetime))
ORDER BY [CRP:PHONE_STATISTICS_TABLE!1!VENDOR_CODE!element],[CRP:PHONE_STATISTICS_TABLE!1!ACTIVITY_DATE!element]
FOR XML EXPLICIT

If I run this statement in the query window the return set is an XML file exactly as i need it.
I am trying to automate daily generation of this XML file, but have not found a way to get the same output.
does anyone have an idea how to solve this ?





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2005 XML: FOR XML PATH -> cdata? stoves SQL Server 2005 1 July 8th, 2008 02:40 AM
How to export the data to XML file format? mbshankar Pro VB 6 2 April 3rd, 2007 12:22 PM
scheduled export to XML file jjhm93 SQL Server 2005 2 December 15th, 2006 02:28 PM
Export SQL To XML shillr SQL Server 2000 0 August 1st, 2006 10:14 AM
How to Export SQL Server Table to XML file??? bekim XML 1 October 4th, 2004 03:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.