Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2005 > SQL Server 2005
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 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, 06:50 AM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default scheduled export to XML file

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 ?
 
Old December 15th, 2006, 12:17 PM
Authorized User
 
Join Date: Dec 2006
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Have you tried using SSIS?

Adam Gossage
Lake Wylie, SC, USA
 
Old December 15th, 2006, 02:28 PM
Registered User
 
Join Date: Nov 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I actually managed using BCP.EXE.






Similar Threads
Thread Thread Starter Forum Replies Last Post
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 from sql 2005 jjhm93 XML 0 November 28th, 2006 07:02 AM
export data from Access to XML file with VB2005 larspersoon Visual Basic 2005 Basics 2 November 25th, 2005 09:41 AM
How to Export SQL Server Table to XML file??? bekim XML 1 October 4th, 2004 03:52 AM
Scheduled the exe file in windows rosalynb VS.NET 2002/2003 1 November 20th, 2003 05:44 PM





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