473,799 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL 2005 to XML

3 New Member
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" >
<customproper ty taskproperty-id="tpc0" value="Unknown" />
<customproper ty taskproperty-id="tpc1" value="17.938 " />
<customproper ty taskproperty-id="tpc2" value="Unknown" />
<customproper ty taskproperty-id="tpc3" value="0" />
<customproper ty 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.Equipment ID = task.EquipmentI D
FOR XML AUTO, TYPE)
FROM VEquipments task
ORDER BY EquipmentDescr
FOR XML AUTO, TYPE
Jun 24 '08 #1
2 1384
deepuv04
227 Recognized Expert New Member
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
yosiasz
3 New Member
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
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10249
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10219
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10025
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9068
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6804
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5461
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4138
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.