code_junkie

Best way to perform dynamic subquery in MS Reporting Services?

Nov 10th, 2011
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. select *,
  2. (select count(*) from tbl2 t2 where t2.tbl1ID = t1.tbl1ID) as cnt
  3. from tbl1 t1
  4.  
  5. declare @tbl1 table
  6. (
  7. tbl1ID int,
  8. prop1 varchar(1),
  9. prop2 varchar(2)
  10. )
  11.  
  12. declare @tbl2 table
  13. (
  14. tbl2ID int,
  15. tbl1ID int
  16. )
  17.  
  18. select *,
  19. (select count(*) from @tbl2 t2 where t2.tbl1ID = t1.tbl1ID) as cnt
  20. from @tbl1 t1
  21.  
  22. select t1.ID, t1.property1, t1.property2, t2.somecol, t2.someothercol
  23. from table t1 left join anothertable t2 on t1.ID = t2.ID
Add Comment
Please, Sign In to add comment