October 11, 2010 at 10:55 am
Can anyone please help me in getting this format. Its really urgent. I really appreicate it. Thanks
Table Temp
Col1 Col2
10 20
30 40
Thanks,
<Records>
<Record>
<Prop Name = "Col1"><Pval>10</Pval></Prop>
<Prop Name = "Col2"><Pval>20</Pval></Pro>
</Record>
<Record>
<Prop Name = "Col1"><Pval>30</Pval></Prop>
<Prop Name = "Col2"><Pval>40</Pval></Prop>
</Record>
</Records>
October 11, 2010 at 10:59 am
I don't see where PVal and such are defined in your table.
Beyond that, are you trying to use "For XML" to produce this from an SQL table, or are you using SQL 2000, or will you be doing this through some means other than T-SQL? You've given too little data to be able to really help much on this.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
October 11, 2010 at 11:08 am
<Pval> need to hard coded.
October 11, 2010 at 11:09 am
I need to write a sql query using for xml and get the data in this format
October 11, 2010 at 11:11 am
What have you tried so far?
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
October 11, 2010 at 11:16 am
SELECT (SELECT top 2 ProductID,EComProductID FROM Products FOR XML AUTO, TYPE).query(
'<Record>{
for $c in /Products
return
<Prop name="PrdouctID">
<Pval >{data($c/@ProductID)}</Pval>
</Prop>,
for $c in /Products
return
<Prop name="EComProductID">
<Pval >{data($c/@EComProductID)}</Pval>
</Prop>
}</Record>')
October 11, 2010 at 12:20 pm
If you can UNPIVOT your data into something like the following:
DECLARE @Unpivot TABLE (RowId int, ColName varchar(50), ColVal int)
INSERT INTO @Unpivot(RowId, ColName, ColVal)
SELECT 1, 'Col1', 10 UNION ALL
SELECT 1, 'Col2', 20 UNION ALL
SELECT 2, 'Col1', 30 UNION ALL
SELECT 2, 'Col2', 40
then your required XML is quite easy to generate using "FOR XML PATH"
SELECT
(
SELECT XIN.ColName AS [@Name], XIN.ColVal AS [Pval]
FROM @Unpivot XIN
WHERE (XIN.RowId = XOUT.RowId)
ORDER BY XIN.ColName
FOR XML PATH('Prop'), Type
) AS Record
FROM @Unpivot XOUT
GROUP BY XOUT.RowId
ORDER BY XOUT.RowId
FOR XML PATH(''), ROOT('Records')
October 11, 2010 at 12:50 pm
Thank You so much......I am working on it to submit to my manager.
Thanks once again
October 11, 2010 at 12:59 pm
I used this sql script and generated the xml file through ssis script task and execute sql task. But I am not getting the version code on the top of the xml file. what should I do to get this. the code I used in script task is as follow.
Dim sw As New IO.StreamWriter(Dts.Variables("User::FilePath").Value.ToString() + Dts.Variables("User::FileName").Value.ToString() + "_1.XML")
sw.Write(Dts.Variables("User::Content").Value.ToString())
sw.Dispose()
'
Dts.TaskResult = ScriptResults.Success
October 12, 2010 at 8:55 am
Can anyone please help me in having the version tag line on the top of the xml file generated by script I provide.
Thanks in advance
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply