How to import sql data in HTML table

  • Hi,

    I am Using HTML format for body for sending DBmail.

    Now my requirement is I want display a table in a mail body.with some that sholud be come from sql table.

    Please help me!

    Thanks in advance!!

  • This should get you on the right track

    DECLARE @Body NVARCHAR(MAX);

    SET @Body = N'<HTML><BODY><TABLE BORDER="1">' + CAST((

    SELECT

    (SELECT name AS 'TD' FOR XML PATH(''), TYPE),

    (SELECT object_id AS 'TD' FOR XML PATH(''), TYPE),

    (SELECT SCHEMA_NAME(schema_id) AS 'TD' FOR XML PATH(''), TYPE)

    FROM

    sys.tables t

    FOR XML RAW('TR'), ELEMENTS

    ) AS NVARCHAR(MAX));

    SET @Body = @Body + '</TABLE></HTML>';

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • Thanks a lot!!

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

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