How to access Dynamics CRM filtered views using a SQL account

  1. Create SQL Account
  2. Add CRMReaderRole role to the account where the organization database to access
  3. Get the GUID for the Dynamics CRM user you would like to impersonate.
  4. Use the Transact-SQL SET CONTEXT_INFO to set the context information to this GUID before querying the filtered view.
    DECLARE  @uid uniqueidentifier
    SET @uid = convert(uniqueidentifier, 'user_guid')
    SET CONTEXT_INFO @uid

    SELECT  *  FROM [FilteredLead]
  5. The query will return the records as if you were connected using the given user's Windows account.  It should be noted that the SET CONTEXT_INFO is only required when establishing the connection, and once set will remain so for the duration of the session



Source: crmland