Formatting a query for an email

  • I am trying to format an email that uses a query to pull data from a table. The table includes three columns: DBName, TicketNumber, Description

    What we want to see in the email is this:

    DBName

    TicketNumber Description

    TicketNumber Description

    TicketNumber Description

    TicketNumber Description

    TicketNumber Description

    DBName

    TicketNumber Description

    TicketNumber Description

    TicketNumber Description

    DBName

    TicketNumber Description

    TicketNumber Description

    TicketNumber Description

    for each entry in the table.

    Here is the current email query:

    DECLARE @count smallint

    DECLARE @queryString nvarchar(400)

    Select @count = count(*)

    From Hold

    set @queryString = 'select DBName, TicketNumber, BillStatusDesc

    FROM Hold

    where dbname in (select dbname from TempHold)

    order by DBName, TicketNumber'

    if @count > 0

    begin

    print @queryString

    EXEC master..xp_sendmail

    @recipients = 'mbookout@backofficemd.com',

    @message = 'Below are Centricity databases that have electronic claims that have been in the Hold status for more than 30 days along with the number of claims in each status.',

    @query = @queryString,

    @subject = 'Hold',

    @no_header = TRUE,

    @width = 600,

    @separator = '-',

    @set_user = 'dbo',

    @dbuse = 'WSBInternal'

    end

    else

    begin

    EXEC master..xp_sendmail

    @recipients = 'mbookout@backofficemd.com',

    @message = 'There were no Centricity Hold status issues today!',

    @subject = 'Hold status issues'

    end

    Any ideas would be greatly appreciated!

  • Well, of course, as soon as I posted, I figured it out 🙂

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

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