In case you have your own slow SQL query, you can optimize it automatically here.
For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:
CREATE INDEX so_dtl_idx_opportunity_recid ON SO_Forecast_dtl (Opportunity_RecID);
CREATE INDEX so_opportunity_idx_so_recid_opportunity_rec ON SO_Opportunity (SO_Opp_Status_RecID,Opportunity_RecID);
CREATE INDEX so_audit_idx_year_utc_so_recid_month_utc ON SO_Opportunity_Audit (year_soa_last_updated_utc,SO_Opportunity_Audit_RecId,month_soa_last_updated_utc);
CREATE INDEX so_audit_idx_audit_token ON SO_Opportunity_Audit_Value (audit_token);
CREATE INDEX so_type_idx_so_recid ON SO_Type (SO_Type_RecID);
CREATE INDEX sales_quarterly_idx_fore_year_fore_loc_fore_month ON dbo.sales_forecast_quarterly (fore_quart_year,fore_quart_loc,fore_quart_month);
SELECT
DateName(month,
DateAdd(month,
[sfq].[fore_quart_month],
-1)) AS [Month],
[sfq].[fore_quart_so_rev] AS [Sales Orders Revenue],
[sfq].[fore_quart_so_mar] AS [Sales Orders Margin],
[sfq].[fore_quart_mac_rev] AS [MAC Revenue],
[sfq].[fore_quart_mac_mar] AS [MAC Margin],
[sfq].[fore_quart_total_rev] AS [TOTAL Revenue],
[sfq].[fore_quart_total_mar] AS [TOTAL Margin],
(SELECT
SUM([FORE].[Revenue])
FROM
[SO_Opportunity] [SO]
INNER JOIN
[SO_Type]
ON [SO].[SO_Type_RecID] = [SO_Type].[SO_Type_RecID]
LEFT JOIN
[SO_Opportunity_Audit] [soa]
ON [so].[Opportunity_RecID] = [soa].[Opportunity_RecId]
INNER JOIN
[SO_Opportunity_Audit_Value] [soav]
ON [soa].[SO_Opportunity_Audit_RecId] = [soav].[SO_Opportunity_audit_recid]
LEFT JOIN
[SO_Forecast_dtl] [FORE]
ON [SO].[Opportunity_RecID] = [FORE].[Opportunity_RecID]
WHERE
(
[SO_Type].[Description] NOT LIKE '%MAC%'
AND [SO_Type].[Description] NOT LIKE '%Maint%'
)
AND [soa].year_soa_last_updated_utc = @p_year
AND [soa].month_soa_last_updated_utc = [sfq].[fore_quart_month]
AND [soav].[audit_value] LIKE '%Closed - Won%'
AND [soav].[audit_token] = 'new_value'
AND [so].[SO_Opp_Status_RecID] = 7) AS [Rev]
FROM
[authmanager2].[dbo].[sales_forecast_quarterly] [sfq]
WHERE
[sfq].[fore_quart_year] = @p_year
AND [sfq].[fore_quart_loc] = 'w'
ORDER BY
[sfq].[fore_quart_month]