sp_send_dbmail to include hyperlink

  • I have the following code in place, I need to be able to capture specific application error for each of the Servers that we have.@srv1 variable basically has the value of the number of rows with errors for Server1

    DECLARE @tableHTML NVARCHAR(MAX) ;

    SET @tableHTML =

    N'<H3>Daily App Error</H3>' +

    N'<table border="1"></th>' +

    N'<TR bgcolor="#A9F5F2"><TH>Server<TH><TH>L_Error<TH>TH>History<TH></TR>'+

    N'<TR bgcolor="#A9F5F2"><TD>Server1</TD>'+

    CAST((SELECT

    td = @srv1, ''

    FOR XML PATH('td'), TYPE) AS NVARCHAR(MAX)) +

    <a href="#">CAST((SELECT

    td = Error_Description, ''

    from dbo.DailyErrorLog_Server1

    FOR XML PATH('td'), TYPE) AS NVARCHAR(MAX))</a> + N'</TR>

    </table>'

    I need the end results to be as such

    Server L_Error History

    Server1 5 <Click here for complete list of errors>

    Once user clicks on the History Column data, another window should open with all the errors for Server1

    How do I implement this in the above body which belongs to my sp_send_dbmail.

  • All,

    Appreciate any suggestions, anybody has done this before

    Imagine I have 10 servers to report about

    I am aware that creating a hyperlink means, creating a file to be linked to the hyperlink.If im not mistaken I would need 10 separate files to be tied to the 10 links in the email. I can create these files but how would I do the following:

    1) Update 10 html files with everydays error log. This would generally need to be done everyday prior to send mail task.What kind of process would take care of this ?

    2) When I send the email out with the links and if a user clicks on the link for error. Does he need access to the dir where the link files would be stored ?

  • There are several ways you could do this, none of which involve generating the error reports in advance.

    Two possibilities are either use either a report (SSRS) or ASP.net page that takes the name of the server as a parameter.

    The HTML tag in the email needs to something like:

    <a href='url to your report here' target='_blank'>

    You would then format the value of the href attribute above to pass the name of the server in the page's URL.

    See here for SSRS examples

  • Hello.

    Did you ever figure out how to get this to work? I'm looking to do the same thing - have a link to where the person can open a file within the email I send. Each record will have a different file...

  • I realise this is an old post, but as a question was asked about a solution, I thought I would post.

    This question had also been posted on MSDN, with further information & answers: Link

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

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