473,412 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

SQL 2005 to XML

Hi,

Been spinning on this for whole weekend I can't seem to get what you I want. I have the following xml result from my query. As you notice one of the child elements has the tag identifier VJobs, how can I make it so it says 'task' instead?

<task id="2" name="Saw 1" color="#99ccff" expand="true" />
<task id="3" name="Saw 2" color="#99ccff" expand="true" />
<VJobs id="3" name="Layout#" color="#99ccff">
<customproperty taskproperty-id="tpc0" value="Unknown" />
<customproperty taskproperty-id="tpc1" value="17.938 " />
<customproperty taskproperty-id="tpc2" value="Unknown" />
<customproperty taskproperty-id="tpc3" value="0" />
<customproperty taskproperty-id="tpc4" value="Operator Unknown" />
</VJobs>
</task>

Here is the query, which details jobs to be done on different equipments
SELECT EquipmentID + 1 as id,
EquipmentDescr as [name],
'#99ccff' AS color,
'true' AS [expand],
(SELECT JobID + 2AS id,
'Layout#' AS [name],
'#99ccff' AS color,
(SELECT [taskproperty-id] AS [taskproperty-id],
[value] AS [value]
FROM dbo.JobDetails customproperty
WHERE customproperty.JobID = VJobs.JobID
FOR XML AUTO, TYPE)
FROM VJobs
WHERE VJobs.EquipmentID = task.EquipmentID
FOR XML AUTO, TYPE)
FROM VEquipments task
ORDER BY EquipmentDescr
FOR XML AUTO, TYPE
Jun 24 '08 #1
2 1372
deepuv04
227 Expert 100+
Hi,
try as first take the xml output as string ( into @String) then do a replace function and then convert the string (@string) as xml.

Expand|Select|Wrap|Line Numbers
  1. DECLARE @String VARCHAR(MAX)
  2. SET @String = ''
  3. SET @String = CONVERT(VARCHAR(MAX),SELECT  EquipmentID + 1 as id,
  4.                                         EquipmentDescr as [name],
  5.                                         '#99ccff' AS color,
  6.                                         'true' AS [expand],
  7.                                         (SELECT JobID + 2AS id,
  8.                                                 'Layout#' AS [name],
  9.                                                 '#99ccff' AS color,
  10.                                         (SELECT [taskproperty-id] AS [taskproperty-id],
  11.                                                 [value] AS [value]
  12.                                         FROM dbo.JobDetails customproperty
  13.                                         WHERE customproperty.JobID = VJobs.JobID
  14.                                         FOR XML AUTO, TYPE)
  15.                                         FROM VJobs
  16.                                         WHERE VJobs.EquipmentID = task.EquipmentID
  17.                                         FOR XML AUTO, TYPE)
  18.                                 FROM VEquipments task
  19.                                 ORDER BY EquipmentDescr
  20.                                 FOR XML AUTO, TYPE)
  21.  
  22. SET @String = Replace(@String,'VJobs ','task')
  23.  
  24. SELECT convert(xml,@String)
  25.  
  26.  
  27.  
  28.  
Thanks
Jun 25 '08 #2
deepuv04

Ok is there a grammy award for tech guys cause you deserve one. It works great!!! Thank you so much!
I am using this for a GanttProject display, users are gonna love it.

Youhaev answered another question of mine..that is concatenating xml. That is now possible then since can convert to varchar, concatenate then convert to XML


YEE HAAAA thanks a lot!!!
Jun 25 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.