Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- Id,
- OpportunityId,
- OpportunityName,
- OpportunityStage,
- Email,
- RowNum,
- CreatedDate,
- ToUse,
- FirstName,
- LastName,
- Mobile,
- AccountName,
- AccOppotunityInProgress,
- AccTotalLoanPaid,
- AccTotalClosedLost,
- TotalOppsLoanFunded,
- Useractive,
- EmailOptOut,
- AccountID
- FROM (
- SELECT
- con.Id AS [Id],
- opp.Id AS [OpportunityId],
- acc.Id AS [AccountID],
- opp.Name AS [OpportunityName],
- opp.CreatedDate AS [CreatedDate],
- opp.StageName AS [OpportunityStage],
- con.FirstName AS [FirstName],
- con.LastName AS [LastName],
- con.MobilePhone AS [Mobile],
- con.Useractive__c AS [Useractive],
- con.Email AS [Email],
- con.HasOptedOutOfEmail AS [EmailOptOut],
- acc.Name AS [AccountName],
- acc.Total_Opportunities_in_Progress__c AS [AccOppotunityInProgress],
- acc.Total_Loan_Paid__c AS [AccTotalLoanPaid],
- acc.Total_Closed_Lost__c AS [AccTotalClosedLost],
- opp.Total_Opportunities_Loan_Funded__c AS [TotalOppsLoanFunded],
- CASE WHEN opp.StageName = 'Loan Funded'
- THEN 'X'
- ELSE 'FU'
- END AS ToUse,
- row_number() OVER(PARTITION BY opp_con_role.ContactId ORDER BY opp.CreatedDate DESC) AS RowNum
- From [Opportunitycontactrole] Opp_Con_Role
- INNER JOIN [Opportunity] opp
- On Opp_Con_Role.Opportunityid = Opp.Id
- INNER JOIN [Contact] con
- On Opp_Con_Role.Contactid = Con.Id
- INNER JOIN [account] acc
- ON acc.Id = opp.AccountId
- WHERE con.Email IS NOT NULL OR con.MobilePhone IS NOT NULL
- ) sr ORDER BY sr.OpportunityName
Add Comment
Please, Sign In to add comment