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


I need to create an XML file populated by fields data(eg: SQL Server DB table)


I need to create an XML file populated by fields data(eg: SQL Server DB table)

Author
Message
vsmeruga
vsmeruga
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 35
I have the following XMLSchema template:

<?xml version="1.0" encoding="UTF-8"?>
<DataMarketsFeed xmlns="http://www.test.co.uk/XMLSchema/DataMarketsFeed-v1-2" xmlns:cmn="http://www.test.co.uk/XMLSchema/DataFeedCommon-v1-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DataFeedHeader xmlns="http://www.test.co.uk/XMLSchema/DataFeedCommon-v1-2">
<FeedTargetSchemaVersion>1.2</FeedTargetSchemaVersion>
<Submitter>
<SubmittingFirm>123456</SubmittingFirm>
</Submitter>
<ReportDetails>
<ReportCreationDate>2009-03-12</ReportCreationDate>
<ReportIdentifier>March09</ReportIdentifier>
</ReportDetails>
</DataFeedHeader>
<DataMarketsFeedMsg>
<CoreItemsMkt xmlns="http://www.Test.co.uk/XMLSchema/DataMarketsFeed-v1-2">
<FirmDataRef>123789</FirmDataRef>
<TransRef>123789</TransRef>
<Cancellation>false</Cancellation>
<Status>N</Status>
</CoreItemsMkt>
<Transaction>
<ReportingFirmId>
<ReportingFirmCode type="R">123456</ReportingFirmCode>
</ReportingFirmId>
<TradingDate>2009-02-27</TradingDate>
<TradingTime>08:02:00</TradingTime>
<BuySell>B</BuySell>
<TradingCapacity>P</TradingCapacity>
<InstrumentIdentification>
<InstrumentIdentificationCode type="A">R</InstrumentIdentificationCode>
</InstrumentIdentification>
<MaturityExerciseDeliveryDate>2009-03-31</MaturityExerciseDeliveryDate>
<TypeOfDerivative>F</TypeOfDerivative>
<PriceMultiplier>10</PriceMultiplier>
<UnitPrice>3836</UnitPrice>
<PriceNotation>GBP</PriceNotation>
<Quantity>3.00</Quantity>
<CounterpartyOne>
<CounterpartyCode type="I">QWERTYU</CounterpartyCode>
</CounterpartyOne>
<CounterpartyTwo>
<CounterpartyCode type="I">ASB00037</CounterpartyCode>
</CounterpartyTwo>
<VenueIdentificationTypeCode>M</VenueIdentificationTypeCode>
<UnitPriceTypeCode>C</UnitPriceTypeCode>
</Transaction>
</DataMarketsFeedMsg>
</DataMarketsFeed>
<CoreItemsMkt xmlns="http://www.Test.co.uk/XMLSchema/DataMarketsFeed-v1-2">
<FirmDataRef>123789</FirmDataRef>
<TransRef>123789</TransRef>
<Cancellation>false</Cancellation>
<Status>N</Status>
</CoreItemsMkt>
<Transaction>
<ReportingFirmId>
<ReportingFirmCode type="R">123456</ReportingFirmCode>
</ReportingFirmId>
<TradingDate>2009-02-27</TradingDate>
<TradingTime>08:02:00</TradingTime>
<BuySell>B</BuySell>
<TradingCapacity>P</TradingCapacity>
<InstrumentIdentification>
<InstrumentIdentificationCode type="A">R</InstrumentIdentificationCode>
</InstrumentIdentification>
<MaturityExerciseDeliveryDate>2009-03-31</MaturityExerciseDeliveryDate>
<TypeOfDerivative>F</TypeOfDerivative>
<PriceMultiplier>10</PriceMultiplier>
<UnitPrice>3836</UnitPrice>
<PriceNotation>GBP</PriceNotation>
<Quantity>3.00</Quantity>
<CounterpartyOne>
<CounterpartyCode type="I">QWERTYU</CounterpartyCode>
</CounterpartyOne>
<CounterpartyTwo>
<CounterpartyCode type="I">ASB00037</CounterpartyCode>
</CounterpartyTwo>
<VenueIdentificationTypeCode>M</VenueIdentificationTypeCode>
<UnitPriceTypeCode>C</UnitPriceTypeCode>
</Transaction>
</DataMarketsFeedMsg>
</DataMarketsFeed>

Can some one help me with a SQL Server 2008 - SQL Query to generate the above format ?. Attached the XML output file format as well.
Attachments
XML file format.txt (16 views, 2.00 KB)
Lowell
Lowell
SSC Guru
SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)SSC Guru (74K reputation)

Group: General Forum Members
Points: 74933 Visits: 40985
well, the xml you posted is malformed; it is either missing two tags in the middle, or these two tags below need to be removed from the middle:

</DataMarketsFeedMsg>
</DataMarketsFeed>


the real question is, do you already have a suite of tables in SQL already in place that support the fields that are required in this xml?
without that, you are stuck; it's too much guesswork for us to create the DDL to support it.

What code do you have so far?
what have you tried so far?
can you post the DDL of the tables, and a sample query that pulls the fields out (which we could help convert to xml)


FYI this is valid xml, where i removed the extra tags from the middle; is htis right?
<?xml version="1.0" encoding="UTF-8"?>
<DataMarketsFeed xmlns="http://www.test.co.uk/XMLSchema/DataMarketsFeed-v1-2" xmlns:cmn="http://www.test.co.uk/XMLSchema/DataFeedCommon-v1-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<DataFeedHeader xmlns="http://www.test.co.uk/XMLSchema/DataFeedCommon-v1-2">
<FeedTargetSchemaVersion>1.2</FeedTargetSchemaVersion>
<Submitter>
<SubmittingFirm>123456</SubmittingFirm>
</Submitter>
<ReportDetails>
<ReportCreationDate>2009-03-12</ReportCreationDate>
<ReportIdentifier>March09</ReportIdentifier>
</ReportDetails>
</DataFeedHeader>
<DataMarketsFeedMsg>
<CoreItemsMkt xmlns="http://www.Test.co.uk/XMLSchema/DataMarketsFeed-v1-2">
<FirmDataRef>123789</FirmDataRef>
<TransRef>123789</TransRef>
<Cancellation>false</Cancellation>
<Status>N</Status>
</CoreItemsMkt>
<Transaction>
<ReportingFirmId>
<ReportingFirmCode type="R">123456</ReportingFirmCode>
</ReportingFirmId>
<TradingDate>2009-02-27</TradingDate>
<TradingTime>08:02:00</TradingTime>
<BuySell>B</BuySell>
<TradingCapacity>P</TradingCapacity>
<InstrumentIdentification>
<InstrumentIdentificationCode type="A">R</InstrumentIdentificationCode>
</InstrumentIdentification>
<MaturityExerciseDeliveryDate>2009-03-31</MaturityExerciseDeliveryDate>
<TypeOfDerivative>F</TypeOfDerivative>
<PriceMultiplier>10</PriceMultiplier>
<UnitPrice>3836</UnitPrice>
<PriceNotation>GBP</PriceNotation>
<Quantity>3.00</Quantity>
<CounterpartyOne>
<CounterpartyCode type="I">QWERTYU</CounterpartyCode>
</CounterpartyOne>
<CounterpartyTwo>
<CounterpartyCode type="I">ASB00037</CounterpartyCode>
</CounterpartyTwo>
<VenueIdentificationTypeCode>M</VenueIdentificationTypeCode>
<UnitPriceTypeCode>C</UnitPriceTypeCode>
</Transaction>
<CoreItemsMkt xmlns="http://www.Test.co.uk/XMLSchema/DataMarketsFeed-v1-2">
<FirmDataRef>123789</FirmDataRef>
<TransRef>123789</TransRef>
<Cancellation>false</Cancellation>
<Status>N</Status>
</CoreItemsMkt>
<Transaction>
<ReportingFirmId>
<ReportingFirmCode type="R">123456</ReportingFirmCode>
</ReportingFirmId>
<TradingDate>2009-02-27</TradingDate>
<TradingTime>08:02:00</TradingTime>
<BuySell>B</BuySell>
<TradingCapacity>P</TradingCapacity>
<InstrumentIdentification>
<InstrumentIdentificationCode type="A">R</InstrumentIdentificationCode>
</InstrumentIdentification>
<MaturityExerciseDeliveryDate>2009-03-31</MaturityExerciseDeliveryDate>
<TypeOfDerivative>F</TypeOfDerivative>
<PriceMultiplier>10</PriceMultiplier>
<UnitPrice>3836</UnitPrice>
<PriceNotation>GBP</PriceNotation>
<Quantity>3.00</Quantity>
<CounterpartyOne>
<CounterpartyCode type="I">QWERTYU</CounterpartyCode>
</CounterpartyOne>
<CounterpartyTwo>
<CounterpartyCode type="I">ASB00037</CounterpartyCode>
</CounterpartyTwo>
<VenueIdentificationTypeCode>M</VenueIdentificationTypeCode>
<UnitPriceTypeCode>C</UnitPriceTypeCode>
</Transaction>
</DataMarketsFeedMsg>
</DataMarketsFeed>



Lowell
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
vsmeruga
vsmeruga
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 35
Hi

Here it is Table structure.

CREATE TABLE [dbo].[FSA_REPORT_DATA](
[Unique_Seq_Ref_number] [int] IDENTITY(1,1) NOT NULL,
[Record_Type_Flag] [int] NULL,
[Reporting_Firm_Identification] [nvarchar](50) NULL,
[Reporting_Firm_Code_Type] [nvarchar](1) NULL,
[Trade_Date] [nvarchar](10) NULL,
[Trade_Time] [nvarchar](8) NULL,
[Buy_Sell_Indicator] [nvarchar](1) NULL,
[Trading_Capacity] [nvarchar](1) NULL,
[Instrument_identification] [nvarchar](50) NULL,
[Instrument_Identifier_Type] [nvarchar](1) NULL,
[Instrument_Description] [nvarchar](255) NULL,
[Underlying_Instrument_Identification] [nvarchar](50) NULL,
[Instrument_Type] [nvarchar](1) NULL,
[Maturity_exercise_delivery_date] [nvarchar](10) NULL,
[Derivative_type] [nvarchar](1) NULL,
[Put_call_Identifier] [nvarchar](1) NULL,
[Strike_price] [float] NULL,
[Price_multiplier] [float] NULL,
[Unit_price] [float] NULL,
[Price_notation] [nvarchar](3) NULL,
[Quantity] [float] NULL,
[counterparty_code] [nvarchar](50) NULL,
[Counterparty_code_type] [nvarchar](1) NULL,
[Venue_Identification] [nvarchar](4) NULL,
[Transaction_reference_number] [nvarchar](50) NULL,
[Report_status] [nvarchar](1) NULL,
[Client_Counterparty_2_code] [nvarchar](50) NULL,
[Client_code_type] [nvarchar](1) NULL,
[Venue_Identification_code_type] [nvarchar](1) NULL,
[Unit_price_type_code] [nvarchar](1) NULL,
[Reserved] [nvarchar](50) NULL,
[End_of_Record] [nvarchar](50) NULL,
[FileName] [nvarchar](500) NULL,
[Transaction_status] [nvarchar](500) NULL,
PRIMARY KEY CLUSTERED
(
[Unique_Seq_Ref_number] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

I can give data( 3 records) for this in the evening.

-- Working Query:

select
(select
(
SELECT
'1.2' AS 'FeedTargetSchemaVersion'
FOR XML PATH(''),TYPE
)
,(
select distinct Reporting_Firm_Identification as "Submitter/SubmittingFirm",
substring(convert(varchar,getdate(),120),1,10) as "ReportDetails/ReportCreationDate",
'000GMI' as "ReportDetails/ReportIdentifier"
from dbo.FSA_REPORT_DATA_x where Reporting_Firm_Identification = 114227
FOR XML PATH (''),type
)
FOR XML PATH(''),Root('FSAFeedHeader'),type),
(
SELECT(select ( select ('')fOR XML PATH(''), Root('FSAMarketsFeed'),ELEMENTS XSINIL)FOR XML PATH(''), Root('CoreItemsMkt'),type),

FOR XML PATH(''),Root('FSAMarketsFeedMsg'),type)
FOR XML PATH(''), Root('FSAMarketsFeed'),ELEMENTS XSINIL
vsmeruga
vsmeruga
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 35
Select Query for the above DDL

SELECT [Unique_Seq_Ref_number]
,[Record_Type_Flag]
,[Reporting_Firm_Identification]
,[Reporting_Firm_Code_Type]
,[Trade_Date]
,[Trade_Time]
,[Buy_Sell_Indicator]
,[Trading_Capacity]
,[Instrument_identification]
,[Instrument_Identifier_Type]
,[Instrument_Description]
,[Underlying_Instrument_Identification]
,[Instrument_Type]
,[Maturity_exercise_delivery_date]
,[Derivative_type]
,[Put_call_Identifier]
,[Strike_price]
,[Price_multiplier]
,[Unit_price]
,[Price_notation]
,[Quantity]
,[counterparty_code]
,[Counterparty_code_type]
,[Venue_Identification]
,[Transaction_reference_number]
,[Report_status]
,[Client_Counterparty_2_code]
,[Client_code_type]
,[Venue_Identification_code_type]
,[Unit_price_type_code]
,[Reserved]
,[End_of_Record]
,[FileName]
,[Transaction_status]
FROM [FSAReportDB].[dbo].[FSA_REPORT_DATA]
vsmeruga
vsmeruga
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 35
Hi

Attached XML output file to be generated one more time. If you say i missed/put some extra tags in my first post. it is corrected now.

Many thanks
VJ
Attachments
XML file format.txt (82 views, 2.00 KB)
vsmeruga
vsmeruga
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 35
Hi

As requested , i have uploaded DDL script to create table and few rows to insert . please help me with SQL query to generate XML.

Many thanks
Attachments
fsa_qry.txt (26 views, 4.00 KB)
vsmeruga
vsmeruga
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 35
Hi Lowell

Can you help me on the query please.

Many thanks
V
vsmeruga
vsmeruga
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
Points: 25 Visits: 35
Firiends any one has worked on creating a SQL to generate this kind of XML, Help me please.
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