I have a View that is the union of 3 views. The view stands to let users see the qty of leads, Archived Leads and Opportunities broken down by marketing Project.
I have various calculations in the 3 views that make up my Union View and all is working well.
I now have the requirement to add a link into another table (Forecast). This table links directly to the Opportunity Table and each Opportuntity can have several forecasts.
However I try and add this into my existing view, I end up with duplicate Opportunities (if there are 3 forecast Values there are 3 Opportunities).
I have a total mental block on this - please can someone explain in thoery how I need to get around this issue. I am sure that it is possible. I have tried various group by's etc.
The View below is my starting point. the forecast table that I am trying to add into it just contains 3 fields:
Opportunity_id
Forecast_date
Forecast_Value
Any help would be gratefully appreciated.
I have various calculations in the 3 views that make up my Union View and all is working well.
I now have the requirement to add a link into another table (Forecast). This table links directly to the Opportunity Table and each Opportuntity can have several forecasts.
However I try and add this into my existing view, I end up with duplicate Opportunities (if there are 3 forecast Values there are 3 Opportunities).
I have a total mental block on this - please can someone explain in thoery how I need to get around this issue. I am sure that it is possible. I have tried various group by's etc.
The View below is my starting point. the forecast table that I am trying to add into it just contains 3 fields:
Opportunity_id
Forecast_date
Forecast_Value
Any help would be gratefully appreciated.
Code:
CREATE View Vw_Sales_Pipeline_1
as
SELECT dbo.Marketing_Project.Marketing_Project_Name,
dbo.Vw_MP_Arch_Leads.[Create Date],
dbo.Vw_MP_Arch_Leads.[Company name],
dbo.Vw_MP_Arch_Leads.[Full Name],
dbo.Vw_MP_Arch_Leads.[Lead Days in Cycle],
dbo.Vw_MP_Arch_Leads.[Site ID],
dbo.Vw_MP_Arch_Leads.[Acc Manager],
dbo.Vw_MP_Arch_Leads.[Territory],
dbo.Vw_MP_Arch_Leads.[Archived Reason],
dbo.Vw_MP_Arch_Leads.[City],
dbo.Vw_MP_Arch_Leads.[Country],
dbo.Vw_MP_Arch_Leads.[Clas7],
dbo.Vw_MP_Arch_Leads.[Region Name],
'' as 'Clas4',
'' as 'Solution Type',
'' as 'Last Called',
'Archived Lead' as [Pipeline Stage],
'' as 'Opp Name',
'' as 'Est Dec Date',
'' as 'Est Rev Date',
'' as 'Act Dec Date',
'' as 'Act Rev Date',
'' as 'Opp Status',
'' as 'Progress',
'' as 'Result 1',
'' as 'Est Total',
'' as 'Opp Curr',
'' as 'Opp Lead Days',
'' as 'Opp Total Days',
'' as 'Prob Value',
'' as 'Prob Inc Dec',
'' as 'Opp Clas8',
'' as 'Opp Won Against comp',
'' as 'Opp Lost against Comp',
'' as 'Opp Total Desc',
'' as 'Opp Prob to Win',
'' as 'GBP Est Total',
'' as 'GBP Prob Total'
FROM dbo.Marketing_Project RIGHT OUTER JOIN
dbo.Vw_MP_Arch_Leads ON dbo.Marketing_Project.Marketing_Project_Id = dbo.Vw_MP_Arch_Leads.Lead_Source_Id
UNION ALL
SELECT dbo.Marketing_Project.Marketing_Project_Name,
dbo.Vw_MP_Leads.[Create Date],
dbo.Vw_MP_Leads.[Company name],
dbo.Vw_MP_Leads.[Full Name],
dbo.Vw_MP_Leads.[Lead Days in Cycle],
dbo.Vw_MP_Leads.[Site ID],
dbo.Vw_MP_Leads.[Acc Manager],
dbo.Vw_MP_Leads.[Territory],
'' as 'Arch Reason',
dbo.Vw_MP_Leads.[City],
dbo.Vw_MP_Leads.[Country],
dbo.Vw_MP_Leads.[Clas7],
dbo.Vw_MP_Leads.[Region Name],
dbo.Vw_MP_Leads.[Clas4],
dbo.Vw_MP_Leads.[Solution Type],
dbo.Vw_MP_Leads.[Date Last Called],
'Current Lead' as [Pipeline Stage],
'' as 'Opp Name',
'' as 'Est Dec Date',
'' as 'Est Rev Date',
'' as 'Act Dec Date',
'' as 'Act Rev Date',
'' as 'Opp Status',
'' as 'Progress',
'' as 'Result 1',
'' as 'Est Total',
'' as 'Opp Curr',
'' as 'Opp Lead Days',
'' as 'Opp Total Days',
'' as 'Prob Value',
'' as 'Prob Inc Dec',
'' as 'Opp Clas8',
'' as 'Opp Won Against comp',
'' as 'Opp Lost against Comp',
'' as 'Opp Total Desc',
'' as 'Opp Prob to Win',
'' as 'GBP Est Total',
'' as 'GBP Prob Total'
FROM dbo.Marketing_Project RIGHT OUTER JOIN
dbo.Vw_MP_Leads ON dbo.Marketing_Project.Marketing_Project_Id = dbo.Vw_MP_Leads.Lead_Source_Id
UNION ALL
SELECT dbo.Marketing_Project.Marketing_Project_Name,
dbo.Vw_MP_Opportunities.[Create Date],
dbo.Vw_MP_Opportunities.[Opp Company Name],
dbo.Vw_MP_Opportunities.[Opp Full Name],
dbo.Vw_MP_Opportunities.[Opp Days in Cycle],
dbo.Vw_MP_Opportunities.[Opp Site],
dbo.Vw_MP_Opportunities.[Opp Account Manager],
dbo.Vw_MP_Opportunities.[Opp Territory],
'' AS 'Arch Reason',
dbo.Vw_MP_Opportunities.[Opp City],
dbo.Vw_MP_Opportunities.[Opp country],
dbo.Vw_MP_Opportunities.[Opp Clas7],
dbo.Vw_MP_Opportunities.[Region Name],
dbo.Vw_MP_Opportunities.[Opp Clas4],
dbo.Vw_MP_Opportunities.[Opp Solution Type],
'' AS 'last Called',
'Opportunity' AS [Pipeline Stage],
dbo.Vw_MP_Opportunities.[Opp Name],
dbo.Vw_MP_Opportunities.[Est Dec Date],
dbo.Vw_MP_Opportunities.[Est Rev Date],
dbo.Vw_MP_Opportunities.[Act Dec Date],
dbo.Vw_MP_Opportunities.[Act Rev Date],
dbo.Vw_MP_Opportunities.[Opp Status],
dbo.Vw_MP_Opportunities.Progress,
dbo.Vw_MP_Opportunities.[Result 1],
dbo.Vw_MP_Opportunities.[Est Total],
dbo.Vw_MP_Opportunities.[Opp Curr],
dbo.Vw_MP_Opportunities.[Opp Lead Days],
dbo.Vw_MP_Opportunities.[Opp Total Days],
dbo.Vw_MP_Opportunities.[Prob Value],
dbo.Vw_MP_Opportunities.[Prob Inc Dec],
dbo.Vw_MP_Opportunities.[Opp Clas8],
dbo.Vw_MP_Opportunities.[Opp Won Against comp],
dbo.Vw_MP_Opportunities.[Opp Lost Against Comp],
dbo.Vw_MP_Opportunities.[Opp Total Desc],
dbo.Vw_MP_Opportunities.[Opp Prob to Win],
ROUND(dbo.Vw_MP_Opportunities.[GBP Est Total], 2),
ROUND(dbo.Vw_MP_Opportunities.[GBP Prob Total], 2)
FROM dbo.Marketing_Project RIGHT OUTER JOIN
dbo.Vw_MP_Opportunities ON dbo.Marketing_Project.Marketing_Project_Id = dbo.Vw_MP_Opportunities.Lead_Source_Id