--I Am Using SQL Server 2008 R2 And Report Builder 3.0--So what I am trying to do is, I have a report that generates of how many Funded contracts are funded within the year 2014 of each month and in the end of the year its suppose to total up the funded contracts of all the months a column called "Year to Date"My problem is not that bad, So when the user enters the dates of their choosing it shows how many funded contracts within the month they chose. So if they input @Begin_date 01/02/2014 and @End_date 03/02/2014. *THEY SHOULD ONLY SEE THOSE 3 MONTHS IN RANGE* So my query does give the user the funded contracts within their months EXCEPT it shows all the months even though my query doesn't show the funded contracts in other months they haven't chosen. In simpler terms I don't want this output when User enters their credentials:@begin_Date 01/01/2014 @End_date 02/01/2014Jan Feb Mar May Jun Jul Aug Sep Oct Nov Dec YTD1 1 0 0 0 0 0 0 0 0 0 20 1 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1I want this for the user output when they enter their credentials@begin_Date 01/01/2014 @End_date 02/01/2014Jan Feb YTD1 1 20 1 11 0 1This is my Query Alter Proc spGetAdminTotalYTD(@Begin_Date DATETIME, @End_Date DATETIME, @program int=null) As Declare @year int Set @year = 2014BeginSELECT d.name, a.dealer_code, b.last_name, b.city, b.state, b.phone, c.Funded_date, MONTH(c.Funded_Date), YEAR(c.Funded_Date), COUNT(CASE WHEN MONTH(c.Funded_date) = 1 THEN 1 ELSE NULL END) JANUARY , COUNT(CASE WHEN MONTH(c.Funded_date) = 2 THEN 1 ELSE NULL END) Feburary , COUNT(CASE WHEN MONTH(c.Funded_date) = 3 THEN 1 ELSE NULL END) March , COUNT(CASE WHEN MONTH(c.Funded_date) = 4 THEN 1 ELSE NULL END) April , COUNT(CASE WHEN MONTH(c.Funded_date) = 5 THEN 1 ELSE NULL END) May , COUNT(CASE WHEN MONTH(c.Funded_date) = 6 THEN 1 ELSE NULL END) June , COUNT(CASE WHEN MONTH(c.Funded_date) = 7 THEN 1 ELSE NULL END) July , COUNT(CASE WHEN MONTH(c.Funded_date) = 8 THEN 1 ELSE NULL END) August , COUNT(CASE WHEN MONTH(c.Funded_date) = 9 THEN 1 ELSE NULL END) September , COUNT(CASE WHEN MONTH(c.Funded_date) = 10 THEN 1 ELSE NULL END) October , COUNT(CASE WHEN MONTH(c.Funded_date) = 11 THEN 1 ELSE NULL END) November , COUNT(CASE WHEN MONTH(c.Funded_date) = 12 THEN 1 ELSE NULL END) December, COUNT(1) AS YTDFROM tdealer a JOIN tContact b ON a.contact_id = b.contact_id JOIN tcontract c ON a.dealer_id = c.dealer_id JOIN tCompany d ON c.company_id = d.company_idWHERE d.company_id = @program AND c.Funded_date >= DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-5,0) And YEAR(c.Funded_date) = @Year And c.Funded_date < DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, 0) And (c.funded_date) between @Begin_Date And @End_DateGROUP BY d.name, a.dealer_code, b.last_name, b.city, b.state, b.phone, c.funded_dateendexec spGetAdminTotalYTD '01/04/2014', '05/30/2014', '47'
↧