I have 2 queries, with Parameters. I can get them to report individualy, however I want both tables on 1 report. The problem is, a subreport seems to be problematic using parameters… My 2 queries are:
SELECT A.Store_Number, A.GC_Sold, B.Total_Cars
FROM (SELECT Store_Number, COUNT_BIG(Quantity_Sold) AS GC_Sold
FROM Invoice_Detail_Tb
WHERE (Invoice_Date BETWEEN CONVERT(DATETIME, @startdate, 102) AND CONVERT(DATETIME, @enddate, 102)) AND (JLI_Category_Code = 'gc') AND (Invoice_Detail_Code LIKE 'jlgc%') AND (Invoice_Detail_Type = 'Item')
GROUP BY Store_Number) AS A INNER JOIN
(SELECT Store_Number, SUM(Vehicle_Count) AS Total_Cars
FROM Daily_Sales_Tb
WHERE (Operations_Day BETWEEN CONVERT(DATETIME, @startdate, 102) AND CONVERT(DATETIME, @enddate, 102))
GROUP BY Store_Number) AS B ON A.Store_Number = B.Store_Number
This output gives me data for a date range and looks like this:
Store gc sold total cars
1 5 8
2 6 9
3 7 10
My Second query is:
SELECT A.Store_Number, A.GC_Sold, B.Total_Cars
FROM (SELECT Store_Number, COUNT_BIG(Quantity_Sold) AS GC_Sold
FROM Invoice_Detail_Tb
WHERE (Invoice_Date = CONVERT(DATETIME, @enddate, 102)) AND (JLI_Category_Code = 'gc') AND (Invoice_Detail_Code LIKE 'jlgc%') AND (Invoice_Detail_Type = 'Item')
GROUP BY Store_Number) AS A INNER JOIN
(SELECT Store_Number, SUM(Vehicle_Count) AS Total_Cars
FROM Daily_Sales_Tb
WHERE (Operations_Day = CONVERT(DATETIME, @enddate, 102))
GROUP BY Store_Number) AS B ON A.Store_Number = B.Store_Number
This output returns data just for enddate. and looks identical to the table above.
The user is picking the startdate and enddate on a windows form and pushing “go”. The parameters are then passed to report viewer… Any ideas?
If this is a SQL Server Reporting Services report, then you can add multiple data sets. In your case, the first would use the first query, the second data set would use the second query with both data sets using the same shared data source (=> database connection).
Then you can add two tables to the report – one referencing the first data set as its data source, the other referencing the second data set.
The same can be modeled for local reports.