I use multiple similar datasets (the data coming from Stored Procedures) that I use in a Tablix in an SSRS report. I need to show the data from these similar-(in metadata)-but-disparate(in result set data) Stored Procedures side-by-side (in each row of the result set in the Tablix).
The data returned from a Stored Proc will contain a record for week1 values, and another record for week2 values for a given ItemCode, but I need to show these side-by-side; IOW, data like this:
ITEMCODE WEEK1 WEEK2
-------- ----- -----
1 11 0
. . .
1 0 42
2 7 0
. . .
2 0 8
...needs to display on the report as:
ITEMCODE WEEK1 WEEK2
-------- ----- -----
1 11 42
2 7 8
Based on an answer here, I tried to accomplish this using Expressions for the "Week1" and "Week2" data fields:
Week 1 Expression:
=IIF((Fields!Week.Value="WK1"),Fields!Price.Value,"")
Week 2 Expression:
=IIf(Lookup(Fields!ItemCode.Value, Fields!ItemCode.Value, Fields!Week.Value, "RockBottomRollup_Craftworks")
="WK2", Lookup(Fields!ItemCode.Value, Fields!ItemCode.Value, Fields!Price.Value,
"RockBottomRollup_Craftworks"), "")
...but using those expressions I hear only deafening silence for week2 (the "5/22/2016 - 5/28-2016" column in the screen shot):
What do I need to do to concentrate the week1 and week2 rows into single rows for each ItemCode?
UPDATE
I think what I need to do is have the expression for week2 not only be tied to the ItemCode value, but also to the Member value.
However, being the VBScript novice/doofus (sp?) that I am, I don't know what syntax is needed to make that happen.
Do I need to change the Week 2 Expression to something like this:
=IIf(Lookup(Fields!ItemCode.Value AND Fields!Member.Value, Fields!ItemCode.Value, Fields!Week.Value,
"RockBottomRollup_Craftworks")
="WK2", Lookup(Fields!ItemCode.Value AND Fields!Member.Value, Fields!ItemCode.Value, Fields!Price.Value,
"RockBottomRollup_Craftworks"), "")
...or...???
UPDATE 2
I tried this suggested Expression:
=IIf(Lookup(Fields!ItemCode.Value & " - " & Fields!ShortName.Value,Fields!ItemCode.Value & " - " & Fields!ShortName.Value,
Fields!Week.Value,"RockBottomRollup_Craftworks")
="WK2", Lookup(Fields!ItemCode.Value & " - " & Fields!ShortName.Value, Fields!ItemCode.Value & " - " & Fields!ShortName.Value,
Fields!Price.Value, "RockBottomRollup_Craftworks"), "")
...but still get nothing in the week2 column (there are values for that column in the second half of the report - the first half shows week1 vals, the second half shows week2 vals).
Note: I replaced "Member" with "ShortName" because the former is just the label, and the latter is the actual field name.
Are ampersands (&) really the right thing to use there (as opposed to "AND")?
UPDATE 3
For this to work, do I need to add a second instance of the same dataset to the report, naming it, for example "RockBottomRollup_Craftworks2" and then replacing the existing dataset name in the expression with that (appending the "2")?
UPDATE 4
I like the direction Thomas Inzina is going with this; so would my existing Stored Proc:
IF OBJECT_ID ( 'RockBottomAmalgamated', 'P' ) IS NOT NULL
DROP PROCEDURE RockBottomAmalgamated;
GO
CREATE PROC [dbo].[RockBottomAmalgamated]
@BegDate datetime,
@EndDate datetime,
@SortBy varchar(20)
AS
IF OBJECT_ID('#BaseCraftworksTable', 'U') IS NOT NULL
DROP TABLE #BaseCraftworksTable;
INSERT INTO #BaseCraftworksTable
EXEC sp_ViewPriceMatrix_Variance_RockBottomRollup_Craftworks
@BegDate = @BegDate
,@EndDate = @EndDate
,@SortBy = @SortBy;
SELECT * FROM #BaseCraftworksTable;
...need to change to this:
IF OBJECT_ID ( 'RockBottomAmalgamated', 'P' ) IS NOT NULL
DROP PROCEDURE RockBottomAmalgamated;
GO
CREATE PROC [dbo].[RockBottomAmalgamated]
@BegDate datetime,
@EndDate datetime,
@SortBy varchar(20)
AS
IF OBJECT_ID('#BaseTable', 'U') IS NOT NULL
DROP TABLE #BaseTable;
INSERT INTO #BaseTable
EXEC sp_ViewPriceMatrix_Variance_RockBottomRollup_Craftworks
@BegDate = @BegDate
,@EndDate = @EndDate
,@SortBy = @SortBy;
SELECT #BaseTable.ItemCode, #BaseTable.Price, #BaseTable.Member, #BaseTable.Week, #BaseTable_1.Week as Week2
FROM #BaseTable
INNER JOIN #BaseTable AS #BaseTable_1 ON #BaseTable.ItemCode = #BaseTable_1.ItemCode
WHERE (((#BaseTable.Week)="wk1") AND ((#BaseTable_1.Week)="wk2"));
???
I don't know how I can select from a Stored Proc (as Thomas' answer shows) without first calling the Stored Proc and inserting its returned result set into a temp table or some such. ...or...???
UPDATE 5
Inspired by this link[http://www.sommarskog.se/share_data.html], I tried this, too (adding "OUTPUT" and "BEGIN/COMMIT TRANSACTION" block):
IF OBJECT_ID ( 'RockBottomAmalgamated', 'P' ) IS NOT NULL
DROP PROCEDURE RockBottomAmalgamated;
GO
CREATE PROCEDURE [dbo].[RockBottomAmalgamated]
@BegDate datetime,
@EndDate datetime,
@SortBy varchar(20) OUTPUT
AS
BEGIN TRANSACTION
INSERT INTO #BaseCraftworksTable
EXEC sp_ViewPriceMatrix_Variance_RockBottomRollup_Craftworks
@BegDate = @BegDate
,@EndDate = @EndDate
,@SortBy = @SortBy;
COMMIT TRANSACTION
SELECT * FROM #BaseCraftworksTable;
...but still no results are returned.