Help with this FOR XML EXPLICIT statement

  • this is the XML I WANT:

    <?xml version="1.0" encoding="utf-8" ?>

    - <HelloRequest>

    - <Profile ID="1">

    <Configuration ID="1" PID="1" Name="ScanElapsedTime" UOM="Second">200</Configuration>

    <Configuration ID="2" PID="1" Name="LastScanDate" UOM="Time">XXXXX</Configuration>

    <Configuration ID="3" PID="1" Name="ClientID" UOM="Value">XXXXX</Configuration>

    <Configuration ID="4" PID="1" Name="BO" UOM="IsScanned">TRUE</Configuration>

    <Configuration ID="5" PID="1" Name="Drives" UOM="IsScanned">TRUE</Configuration>

    <Configuration ID="6" PID="1" Name="ErrorLog" UOM="IsScanned">TRUE</Configuration>

    <Configuration ID="7" PID="1" Name="InstalledSoftware" UOM="IsScanned">TRUE</Configuration>

    <Configuration ID="8" PID="1" Name="Memory" UOM="IsScanned">TRUE</Configuration>

    <Configuration ID="9" PID="1" Name="OS" UOM="IsScanned">TRUE</Configuration>

    <Configuration ID="10" PID="1" Name="PhysicalDisks" UOM="IsScanned">TRUE</Configuration>

    <Configuration ID="11" PID="1" Name="Processor" UOM="IsScanned">FALSE</Configuration>

    <Configuration ID="12" PID="1" Name="RunningProgs" UOM="IsScanned">FALSE</Configuration>

    <Configuration ID="13" PID="1" Name="Security" UOM="IsScanned">FALSE</Configuration>

    <Configuration ID="14" PID="1" Name="Services" UOM="IsScanned">FALSE</Configuration>

    <Configuration ID="15" PID="1" Name="StartUp" UOM="IsScanned">FALSE</Configuration>

    <Configuration ID="16" PID="1" Name="TCPIP" UOM="IsScanned">FALSE</Configuration>

    <Configuration ID="17" PID="1" Name="InternetCache" UOM="IsScanned">FALSE</Configuration>

    </Profile>

    </HelloRequest>

    This is the XML I am getting right now :

    <?xml version="1.0" encoding="utf-8" ?>

    - <HelloRequest>

    - <Profile ID="1">

    <Configuration ID="1" PID="1" Name="ScanElapsedTime" UOM="Second" Value="200" />

    <Configuration ID="2" PID="1" Name="LastScanDate" UOM="Time" Value="xxxxx" />

    <Configuration ID="3" PID="1" Name="ClientID" UOM="Value" Value="xxxxx" />

    <Configuration ID="4" PID="1" Name="BO" UOM="IsScanned" Value="TRUE" />

    <Configuration ID="5" PID="1" Name="Drives" UOM="IsScanned" Value="TRUE" />

    <Configuration ID="6" PID="1" Name="ErrorLog" UOM="IsScanned" Value="TRUE" />

    <Configuration ID="7" PID="1" Name="InstalledSoftware" UOM="IsScanned" Value="TRUE" />

    <Configuration ID="8" PID="1" Name="Memory" UOM="IsScanned" Value="TRUE" />

    <Configuration ID="9" PID="1" Name="OS" UOM="IsScanned" Value="TRUE" />

    <Configuration ID="10" PID="1" Name="PhysicalDisks" UOM="IsScanned" Value="TRUE" />

    <Configuration ID="11" PID="1" Name="Processor" UOM="IsScanned" Value="FALSE" />

    <Configuration ID="12" PID="1" Name="RunningProgs" UOM="IsScanned" Value="FALSE" />

    <Configuration ID="13" PID="1" Name="Security" UOM="IsScanned" Value="FALSE" />

    <Configuration ID="14" PID="1" Name="Services" UOM="IsScanned" Value="FALSE" />

    <Configuration ID="15" PID="1" Name="StartUp" UOM="IsScanned" Value="FALSE" />

    <Configuration ID="16" PID="1" Name="TCPIP" UOM="IsScanned" Value="FALSE" />

    <Configuration ID="17" PID="1" Name="InternetCache" UOM="IsScanned" Value="FALSE" />

    </Profile>

    </HelloRequest>

    Hopefully you can notice the difference....anyway here is the statement that gives me what I have right now:

    select 1 as Tag, 0 as Parent, ID as [Configuration!1!ID], PID as [Configuration!1!PID], Name as [Configuration!1!Name], UOM as [Configuration!1!UOM], Value as [Configuration!1!Value] from tblProfile1 where MessageID = '1' for xml explicit

  • This was removed by the editor as SPAM

  • Value is one of those reserved words that may give you a problem... Name is more forgiving.  You may have to use some quotes or brackets around the word "Value"

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Try this...

    select 1 as Tag, 
           0 as Parent, 
           ID as [Configuration!1!ID], 
           PID as [Configuration!1!PID], 
           Name as [Configuration!1!Name], 
           UOM as [Configuration!1!UOM], 
           Value as [Configuration!1!!element] 
    from tblProfile1 
    where MessageID = '1' 
    for xml explicit
  • Here is the way to do what I wanted, thanks everyone for trying to help.

     

    select 1 as Tag, 0 as Parent, ID as [Configuration!1!ID], PID as [Configuration!1!PID], Name as [Configuration!1!Name], UOM as [Configuration!1!UOM], Value as [Configuration!1!Value] from tblProfile1 where MessageID = '1' for xml explicit

  • Thanks for the feedback, Ryan.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply