I have a report and I want to embed a subreport... I seem to have trouble triggering the subreport for a given branch if it exists. Data is in the first post, the main report in the second post and the target report that belongs in a subreport from a drilldown (where data exists) needs to be embedded in the first (third post). VS2010 - copy and paste into SQL ssms and rdl's below - into SSRS.
CREATE VIEW [dbo].[vHierarchyTest]AS SELECT 1 child,NULL parent,'CPO'cname,NULL pname,230 dayz,'bob'NAME,10 obl,0 exc,179 avail,41 fcst,2012 FY,'MGMT'typ,1 lvl,NULL CORPlvl,NULL ORGlvl,NULL SUPERVlvl UNION SELECT 2,1,'VP Branch Efficient','CPO',230,'dave',189,0,0,41,2012,'MGMT',2,'CPO',NULL,NULL UNION SELECT 3,1,'VP Branch Steady','CPO',230 dayz,'barb',189,0,0,41,2012,'MGMT',2,'CPO',NULL,NULL UNION SELECT 4,1,'VP Branch Improvement','CPO',230 dayz,'jill',189,0,0,41,2012,'MGMT',2,'CPO',NULL,NULL UNION SELECT 5,2,'Branch 1','VP Branch Efficient',240 dayz,'sandy',199,0,0,51,2012 FiscalYea,'MGMT'typr,3,'CPO','VP Branch Efficient',NULL UNION SELECT 6,2,'Branch 1','VP Branch Efficient',240 dayz,'betty',199,0,0,51,2012 FiscalYea,'MGMT'typr,3,'CPO','VP Branch Efficient',NULL UNION SELECT 7,3,'Branch 2','VP Branch Steady',240 dayz,'celia'name,199,0,0,51,2012,'MGMT',3,'CPO','VP Branch Steady',NULL UNION SELECT 8,4,'Branch 3','VP Branch Improvement',240 dayz,'jim',199,0,0,51,2012,'MGMT',3,'CPO','VP Branch Improvement',NULL UNION SELECT 9,5,'StoreMgt 1','Branch 1',250,'todd',209,0,0,41,2012,'MGMT',4,'CPO','VP Branch Efficient',NULL UNION SELECT 10,6,'StoreMgt 2','Branch 2',250,'dan',209,0,0,41,2012,'MGMT',4,'CPO','VP Branch Steady',NULL UNION SELECT 11,7,'StoreMgt 3','Branch 3',250 dayz,'zack',209,0,0,41,2012,'MGMT',4,'CPO','VP Branch Improvement',NULL UNION SELECT 12,5,'StoreMgt 1','Branch 1',250,'rich',209,0,0,41,2012,'MGMT',4,'CPO','VP Branch Efficient',NULL UNION SELECT 13,8,'Emp 1','StoreMgt 1',250,'bill',250,0,0,0,2012,'EMPL',5,'CPO','VP Branch Efficient','StoreMgt 1' UNION SELECT 14,8,'Emp 2','StoreMgt 2',250,'art',250,0,0,0,2012,'EMPL',5,'CPO','VP Branch Steady','StoreMgt 2' UNION SELECT 15,8,'Emp 3','StoreMgt 3',250 dayz,'phil',250,0,0,0,2012,'EMPL',5,'CPO','VP Branch Improvement','StoreMgt 3' UNION SELECT 16,9,'Emp 4','StoreMgt 1',250,'dick',250,0,0,0,2012,'EMPL',5,'CPO','VP Branch Efficient','StoreMgt 1' UNION SELECT 17,9,'Emp 5','StoreMgt 2',250,'zoe',250,0,0,0,2012,'EMPL',5,'CPO','VP Branch Steady','StoreMgt 2' UNION SELECT 18,9,'Emp 6','StoreMgt 3',250 dayz,'ann',250,0,0,0,2012,'EMPL',5,'CPO','VP Branch Improvement','StoreMgt 3' UNION SELECT 19,10,'Emp 7','StoreMgt 1',250,'kate',250,0,0,0,2012,'EMPL',5,'CPO','VP Branch Efficient','StoreMgt 1' UNION SELECT 20,10,'Emp 8','StoreMgt 2',250,'john',250,0,0,0,2012,'EMPL',5,'CPO','VP Branch Steady','StoreMgt 2' UNION SELECT 21,10,'Emp 9','StoreMgt 3',250 dayz,'joe',250,0,0,0,2012,'EMPL',5,'CPO','VP Branch Improvement','StoreMgt 3'
CREATE PROC [HierarchyTest] (@FY INT)AS SELECT * FROM vHierarchyTest WHERE FY=@FY AND lvl<5
CREATE PROC PROC [dbo].[HierarchyDrillDownTest] (@FY INT,@cname varchar(50))AS DECLARE @lvl INT,@count INT, @ParentName varchar(50) select @lvl=lvl,@ParentName=pname from vHierarchyTest where cname=@cname SELECT v1.name,v1.cname,@parentname Unit,v1.typ,SUM(v1.dayz) dayz,SUM(v1.obl) obl,SUM(v1.exc) exc,SUM(v1.fcst) fcst,SUM(v1.avail) avail,v1.lvl FROM vHierarchyTest v1 where case when @lvl=2 and v1.corplvl=@parentname then 1 when @lvl=3 and v1.orglvl=@parentname then 1 when @lvl=4 and v1.supervlvl=@parentname then 1 when @lvl=1 then 1 else 0 end =1 and v1.FY=@FY GROUP BY v1.typ,v1.lvl,v1.pname,v1.cname,v1.name
R, J