• parth83.rawal (10/6/2012)


    Worked for me thanks!

    Please also consider this - it is a lot faster and neater IMHO...

    SELECT '#C6CFFF' AS [@bgcolor],

    s.name As

    ,

    '' AS [*], -- Blank, just here to prevent element merging

    product As

    ,

    '' AS [*],

    provider As

    ,

    '' AS [*],

    'width: 210px;min-width: 100px' AS

    ,

    data_source As

    ,

    '' AS [*],

    'center' AS

    ,

    is_linked As

    FROM sys.servers s,syscolumns

    ORDER BY is_linked, s.name

    FOR XML PATH('TR'),ROOT('TABLE')

    I know this looks odd, but that is just because we are using XML to craft HTML. The main difference for this query being that HTML commonly has repeated elements (The TD elements), where XML doesn't tend to.

    What this means for this query is that we need to find a way round the in-built functionality in FOR XML PATH that merges consecutive elements that have the same TAG. The way to stop this is either to alternate between upper and lower case TDs, OR as in this example, to use a blank to break the rule.

    Generally, here we have a ROOT('TABLE') for the whole query, a row tag - FOR XML PATH('TR') and we have attributes, which come at the start of the SELECT for row attributes, but come before each individual TAG.

    I think, in general you will find this method to be faster, neater and easier to produce the correct output.

    For comparison, here is the output from Lowell's method

    <table>

    <tr bgcolor="#C6CFFF">

    <TD>COMP1</TD>

    <TD>SQL Server</TD>

    <TD>SQLNCLI</TD>

    <TD style="width: 210px;min-width: 100px">COMP1</TD style="width: 210px;min-width: 100px">

    <TD align="center">0</TD align="center">

    </tr>

    </table>

    And the output from this method

    <TABLE>

    <TR bgcolor="#C6CFFF">

    <TD>COMP1</TD>

    <TD>SQL Server</TD>

    <TD>SQLNCLI</TD>

    <TD style="width: 210px;min-width: 100px">COMP1</TD>

    <TD align="center">0</TD>

    </TR>

    </TABLE>

    MM



    select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);

  • Forum Etiquette: How to post Reporting Services problems
  • [/url]
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • [/url]
  • How to Post Performance Problems - by Gail Shaw
  • [/url]