multiple attachments using xp_sendmail

  • I need to send multiple attachments in an email using xp_sendmail.  The syntax to do that is simple @attachments = [attachment1];[attachment2]....

    the kicker is that the number of attachments changes with each email I need to send.  Anybody have any idea's? 

     

  • yes, that is doable.

    First you must create some kind of a lookup table where every attachment (path & filename) is stored with an ID.

    Second, create another lookup table where you match each customer (ID) and attachment (ID).

    Third, create a function that takes CustomerID as parameter and returns a string with all attachments viable for this customer.

    There.


    N 56°04'39.16"
    E 12°55'05.25"

  • I thought out the lookup table... I guess I need to specify better where I'm actually stuck at.

    I have a cursor that loops through my lookup table grabbing each file path but how do I get each filepath into one big string??

  • Sometimes I think it takes writing down the problem to find the answer cause I just figured it out... lol

    DECLARE

    attachment_cursor CURSOR FOR

    SELECT ReportName FROM #ReportName

    OPEN

    attachment_cursor

    FETCH

    NEXT FROM attachment_cursor

    INTO

    @MyAttachments

    WHILE

    @@FETCH_STATUS = 0

    BEGIN

    IF LEN(@MyAttachments) > 0

    BEGIN

    SET @FinalAttachments = @MyAttachments + @LastAttachment

    END

    SET @LastAttachment = @MyAttachments

    FETCH NEXT FROM attachment_cursor

    INTO @MyAttachments

    END

    CLOSE

    attachment_cursor

    DEALLOCATE

    attachment_cursor

    --Get attachments

    SELECT @FinalAttachments

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

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