I work with an Insurance Company and have to create a report like this: Excel document with how data is supposed to be on SSRS
My problem is I cannot figure out how I count the different #s of quotes, binds, and submissions in different columns since they all are pulling from the same field tbl_Quote.AccountId
I need to basically Join theses three other queries to have their respective counts and totals in different columns in the result set and I'm not sure how to go about this.
Here is the code:
--RENEWAL BUSINESS
DECLARE @StartDate DATETIME = '05/1/18'
DECLARE @EndDate DATETIME = '11/30/2018'
DECLARE @Policy int = 33
--SUBMISSIONS
SELECT Month(S.CoverageEffDate) [Month], count(distinct Q.AccountId) as [R#ofsubmissions],(SUM(S.NotTaxableSubTotal + S.NotTaxableSubTotal2 + S.TaxableSubTotal)) as RSubmittedPremium
FROM tbl_Quote Q INNER JOIN
tbl_Quote_Scheduled_Locations S ON Q.id = S.Ouote_ID
WHERE (S.CoverageEffDate <= @EndDate) AND (S.CoverageEffDate >= @StartDate) AND (Q.Renewal = 1) AND (Q.Cancellation <> 1) and Q.Endorsement=0 and Q.Policy_ID= @policy
Group By Month(S.CoverageEffDate)
ORDER BY Month;
--QUOTES
SELECT Month(S.CoverageEffDate) [Month], count(distinct Q.AccountId) as [R#ofquotes], (SUM(S.NotTaxableSubTotal + S.NotTaxableSubTotal2 + S.TaxableSubTotal)) as RQuotedPremium
FROM tbl_Quote Q INNER JOIN
tbl_Quote_Scheduled_Locations S ON Q.id = S.Ouote_ID
WHERE (S.CoverageEffDate <= @EndDate) AND (S.CoverageEffDate >= @StartDate) AND (Q.Renewal = 1) AND (Q.Cancellation <> 1) and Q.Endorsement=0 AND (Q.QuoteStatus_OID = 6 OR Q.QuoteStatus_OID = 23 OR Q.QuoteStatus_OID = 10 OR Q.QuoteStatus_OID =8 ) and Q.Policy_ID= @policy
Group By Month(S.CoverageEffDate)
ORDER BY Month;
--BINDS
SELECT Month(S.CoverageEffDate) [Month], count(distinct Q.AccountId) as [R#ofbinds], (SUM(S.NotTaxableSubTotal + S.NotTaxableSubTotal2 + S.TaxableSubTotal)) as RBoundPremium
FROM tbl_Quote Q INNER JOIN
tbl_Quote_Scheduled_Locations S ON Q.id = S.Ouote_ID
WHERE (S.CoverageEffDate <= @EndDate) AND (S.CoverageEffDate >= @StartDate) AND (Q.Renewal = 1) AND (Q.Cancellation <> 1) and Q.Endorsement=0 AND (S.Bound = 1 or Q.QuoteStatus_OID = 23) and Q.Policy_ID= @policy
Group By Month(S.CoverageEffDate)
ORDER BY Month;
I need the query to exactly match the excel document besides the totals since SSRS can do totals.
The code I have provided is only for the Renewal side.