SQL Server FOR XML Explicit

  • I am trying to get XML using a SELECT and For XML EXPLICIT keyword. If the column has NULL value in database, then It does not return the XML attribute. I want the attribute to be there with null or blank value. How can i do it ?

    Example

    SELECT 1 AS Tag,

         NULL AS Parent,

       NULL AS [Root!1!Root],

       NULL AS [Link!2!Id],

       NULL AS [Link!2!Parameters]

      UNION ALL

      SELECT 2 ,

          1,

        NULL,

        LD.Id,

        LD.Parameters    

      From Link LD

      FOR XML EXPLICIT

    It return

    <Root><Link Id="1"/><Link Id="2"/></Root>

    It does not return the attribute "Parameters= """ which i need.

    Desired Output

    <Root><Link Id="1" Parameters= ""/><Link Id="2" Parameters= ""/></Root>

  • I Got the solution for this. It can be done by checking NULL

    ISNULL(Parameters, '')

Viewing 2 posts - 1 through 1 (of 1 total)

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