Skip to content

Instantly share code, notes, and snippets.

@jasonamyers
Created March 27, 2012 01:16
Show Gist options
  • Save jasonamyers/2211439 to your computer and use it in GitHub Desktop.
Save jasonamyers/2211439 to your computer and use it in GitHub Desktop.
MS CRM: Select Email Attachments
SELECT
EA.Body,
EA.ActivityID,
EA.AttachmentNumber,
EA.FileName,
CONVERT(varchar(255), EA.ActivityID) + '_' + CONVERT(varchar(255), EA.AttachmentNumber) + '_' + CONVERT(varchar(255), EA.Filename) AS SaveAsFileName
FROM
FilteredEmail E JOIN
ActivityMimeAttachment EA ON E.ActivityID = EA.ActivityID
WHERE
E.regardingobjecttypecode = 1 or -- Accounts
E.regardingobjecttypecode = 2 or -- Contacts
E.regardingobjecttypecode = 3 or -- Opportunities
E.regardingobjecttypecode = 4 -- Leads
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment