I have been searching on the net for the last couple of days and unfortunately cannot find quite what I am looking for. I have a SQL Server 2012 table that contains 2 columns, one is PurchaseOrder DataType varchar(10) the other is Data with a DataType of XML. Currently what is happening ever few hours a stored procedure is run to check a number of table for a value and then create a PurchaseOrder in the desired XML format. This has been achieved and validated by the company that I am going to be sending the data to. The issue I now have is I want to create a SSIS package that looks at this table and creates multiple xml files with the contents of the Data field "not putting the contents in to one long line" and then using the PurchaseOrder field for the file name. I have found various part solutions e.g. using a Script task as there is no native XML Destination in SSIS but struggling and being quite new to SSIS not getting anywhere fast. Can anyone offer any help, guidance, youtube links or even a part way there package.
Thanks P
Further to the above question I have tried to go about it using the bcp command, below is the following code that works great just looking at the top 1 record
DECLARE @fileName VARCHAR(50)
DECLARE @sqlStr VARCHAR(1000)
DECLARE @sqlCmd VARCHAR(1000)
SET @fileName = 'C:\Temp\test.xml'
SET @sqlStr = 'select TOP 1 Data from DatabaseName.dbo.OutputXML'
SET @sqlCmd = 'bcp "' + @sqlStr + '" queryout ' + @fileName + '
-w -T -S Server\Instance'
EXEC xp_cmdshell @sqlCmd
What I have then done is add this in to a cursor, which again works to a point, it creates my files, using the purchaseorder as the file name and outputs the relevant information but it no longer holds the proper xml format, it goes back to looking like a string with none of the original formatting, is this because I am imbedding it in the cursor?? Below is the code that I am using
DECLARE @fileName VARCHAR(50)
DECLARE @sqlStr VARCHAR(1000)
DECLARE @sqlCmd VARCHAR(1000)
DECLARE xml_cursor CURSOR FOR
SELECT PurchaseOrder from DatabaseName.dbo.OutputXML
OPEN xml_cursor
FETCH NEXT FROM xml_cursor INTO @fileName
WHILE @@FETCH_STATUS = 0
BEGIN
SET @fileName = 'C:\Temp\'+@fileName+'.xml'
SET @sqlStr = 'select Data from DatabaseName.dbo.OutputXML'
SET @sqlCmd = 'bcp "' + @sqlStr + '" queryout ' + @fileName + '
-w -T -S Server\Instance'
EXEC xp_cmdshell @sqlCmd
FETCH NEXT FROM xml_cursor into @fileName
END
CLOSE xml_cursor
DEALLOCATE xml_cursor