SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Automated XML file


Automated XML file

Author
Message
durocshark
durocshark
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 6
I was given this code from a vendor to export customer data from our ERP system into their system. I need to automate this and save it as a formatted (with CR's) XML file.

SELECT TOP (100) PERCENT Customer_1.Name AS BilltoName, dbo.Address.Address1 AS BillToAddress, dbo.Address.City AS BillToCity, dbo.Address.Zip AS BillToZip, 
dbo.Address.State AS BilltoState, dbo.Customer.Name AS ShiptoName, Address_1.Address1 AS ShipToAddress, Address_1.City AS ShipToCity, Address_1.Zip AS ShipToZip,
Address_1.State AS ShipToState, dbo.Customer.DefManufacturingPlantLink, dbo.Customer.BillToLink, dbo.Customer.CustomerLink AS shiptolink,
dbo.Customer.CustomerShortName AS ShortName
FROM dbo.Customer INNER JOIN
dbo.Customer AS Customer_1 ON dbo.Customer.BillToLink = Customer_1.CustomerLink INNER JOIN
dbo.Address ON Customer_1.CustomerLink = dbo.Address.CustomerLink INNER JOIN
dbo.Address AS Address_1 ON dbo.Customer.CustomerLink = Address_1.CustomerLink
WHERE (dbo.Customer.DefManufacturingPlantLink <> 2)
for xml path ('Customer'), root ('Customers')


This code works perfectly fine in SSMS as a straight query. But I can't keep running this manually and need to save it as an XML file on a network file share.

I'm a total n00b and have no idea where to even start. I can make it a SQL Server Agent Job, but don't know what to add to make it save the output.

Thanks!
Eirikur Eiriksson
Eirikur Eiriksson
SSC Guru
SSC Guru (159K reputation)SSC Guru (159K reputation)SSC Guru (159K reputation)SSC Guru (159K reputation)SSC Guru (159K reputation)SSC Guru (159K reputation)SSC Guru (159K reputation)SSC Guru (159K reputation)

Group: General Forum Members
Points: 159143 Visits: 23308
You can use BCP to export the XML to the file system
Cool
durocshark
durocshark
Grasshopper
Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)Grasshopper (23 reputation)

Group: General Forum Members
Points: 23 Visits: 6
Eirikur Eiriksson - Wednesday, January 31, 2018 12:24 PM
You can use BCP to export the XML to the file system
Cool

Thanks I've seen that mentioned but I can't find a walkthrough that works with my limited skills.

Subramaniam Chandrasekar
Subramaniam Chandrasekar
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3506 Visits: 531
durocshark - Wednesday, January 31, 2018 10:54 AM
I was given this code from a vendor to export customer data from our ERP system into their system. I need to automate this and save it as a formatted (with CR's) XML file.

SELECT TOP (100) PERCENT Customer_1.Name AS BilltoName, dbo.Address.Address1 AS BillToAddress, dbo.Address.City AS BillToCity, dbo.Address.Zip AS BillToZip, 
dbo.Address.State AS BilltoState, dbo.Customer.Name AS ShiptoName, Address_1.Address1 AS ShipToAddress, Address_1.City AS ShipToCity, Address_1.Zip AS ShipToZip,
Address_1.State AS ShipToState, dbo.Customer.DefManufacturingPlantLink, dbo.Customer.BillToLink, dbo.Customer.CustomerLink AS shiptolink,
dbo.Customer.CustomerShortName AS ShortName
FROM dbo.Customer INNER JOIN
dbo.Customer AS Customer_1 ON dbo.Customer.BillToLink = Customer_1.CustomerLink INNER JOIN
dbo.Address ON Customer_1.CustomerLink = dbo.Address.CustomerLink INNER JOIN
dbo.Address AS Address_1 ON dbo.Customer.CustomerLink = Address_1.CustomerLink
WHERE (dbo.Customer.DefManufacturingPlantLink <> 2)
for xml path ('Customer'), root ('Customers')


This code works perfectly fine in SSMS as a straight query. But I can't keep running this manually and need to save it as an XML file on a network file share.

I'm a total n00b and have no idea where to even start. I can make it a SQL Server Agent Job, but don't know what to add to make it save the output.

Thanks!

We'd tried to use SSIS, Problem is we need to write .net code to do the automation.

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search