title: Missing Rows using Tablix in SSRS
body: <p>Something very confusing has come up. I posted this question in MS' SQL Server community last week, but after 125 views, no one has taken a stab at the problem. Anyway, here goes;</p>
  
  <p>I'm using Visual Studio 2008 and have created a report that returns the number of current members assigned to a particular doctor in our group. Then, for a detail, one can click on the doctor's name and it will bring up a subreport that details the demographics of his members; name, address, DoB, gender, etc.</p>
  
  <p>During debugging the subreport, I hard coded a particular doctor and effective date (to get the current members only). Everything seemed to be working fine - and, for the doctor I chose, it actually was working fine. Then, I checked to ensure that the subreport came up properly, but still used this same doctor to test that, since I'd already recorded what he should have and that made it easier.</p>
  
  <p>When we tested the report before pushing it out, we looked at the very first doctor in the list. This doctor is one we commonly use for testing because his name is alphabetically first, he also has a buttload of patients. So, because we used him for other purposes, we already knew what his count should be and the main report properly showed it to be the correct number. Because of his high member load, I didn't use him for my debugging.</p>
  
  <p>Then, we clicked on him to get his detail and, for some reason, decided to check the list. It was two short.</p>
  
  <p>That was odd, we thought. The count showed the correct number, but the subreport detail returned two less.</p>
  
  <p>So, I dumped the detail into Excel to see who was missing. Turns out, this doctor happens to have two members who share a name with two other members. The second of each pair was missing.</p>
  
  <p>I checked the query in SQL, it returned everyone, even the duplicate named members, no problem. I ran the query while in the Query Builder in SSRS - well, Visual Studio - and, again, it returned the correct members.</p>
  
  <p>Thinking that it might be something to do with using a filter, I changed the query to use a WHERE, rather than a dataset filter, and ran the report; it lost those two. I ran it in the query designer with the WHERE and it returned the correct count.</p>
  
  <p>For some reason, we can't fathom why, when the query is run as part of the report, it loses the two duplicately named members, but when run as a query, it works fine.</p>
  
  <p>I can't see why the name should matter. It's not used for anything, not as a criteria for a WHERE or anything else, and not as a filter.</p>
  
  <p>Below is the query in the three forms I've tested it;</p>
  
  <pre class="lang-SQL prettyprint-override"><code>/*This is the hard-coded version*/
  SELECT
    RTRIM(LastName) + ', ' + RTRIM(FirstName) AS Name,
    RTRIM(MemberID) AS MemberID,
    RTRIM(MRN) AS MRN,
    RTRIM(Last_Visit_STATUS) AS Last_Visit_STATUS,
    CAST(DOB AS date) AS DoB,
    RTRIM(Gender) AS Gender,
    RTRIM(Street) AS Street,
    RTRIM(City) AS City,
    RTRIM([State]) AS [State],
    RTRIM(Zip) AS Zip,
    RTRIM(Phone) AS Phone,
    RTRIM(Eff_Period) AS Eff_Period,
    RTRIM(PCP_NPI) AS PCP_NPI
  FROM
    THPGPRODSQL.UHC_MA_Risk.dbo.UHC_MA_Risk_Current_Membership
  WHERE
    Eff_Period = '201503'
    AND PCP_NPI = '[NPI # goes here]';
  
  /*This is the version that uses the dataset filters of;
    @CurEffPer
    @PCP_NPI*/
  SELECT
    RTRIM(LastName) + ', ' + RTRIM(FirstName) AS Name,
    RTRIM(MemberID) AS MemberID,
    RTRIM(MRN) AS MRN,
    RTRIM(Last_Visit_STATUS) AS Last_Visit_STATUS,
    CAST(DOB AS date) AS DoB,
    RTRIM(Gender) AS Gender,
    RTRIM(Street) AS Street,
    RTRIM(City) AS City,
    RTRIM([State]) AS [State],
    RTRIM(Zip) AS Zip,
    RTRIM(Phone) AS Phone,
    RTRIM(Eff_Period) AS Eff_Period, -- uses the @CurEffPer parameter
    RTRIM(PCP_NPI) AS PCP_NPI        -- uses the @PCP_NPI parameter
  FROM
    THPGPRODSQL.UHC_MA_Risk.dbo.UHC_MA_Risk_Current_Membership;
  
  /*This is the version that uses the WHERE clause*/
  SELECT
    RTRIM(LastName) + ', ' + RTRIM(FirstName) AS Name,
    RTRIM(MemberID) AS MemberID,
    RTRIM(MRN) AS MRN,
    RTRIM(Last_Visit_STATUS) AS Last_Visit_STATUS,
    CAST(DOB AS date) AS DoB,
    RTRIM(Gender) AS Gender,
    RTRIM(Street) AS Street,
    RTRIM(City) AS City,
    RTRIM([State]) AS [State],
    RTRIM(Zip) AS Zip,
    RTRIM(Phone) AS Phone,
    RTRIM(Eff_Period) AS Eff_Period,
    RTRIM(PCP_NPI) AS PCP_NPI
  FROM
    THPGPRODSQL.UHC_MA_Risk.dbo.UHC_MA_Risk_Current_Membership
  WHERE
    Eff_Period = @CurEffPer
    AND PCP_NPI = @PCP_NPI;
  </code></pre>
  
  <p>It doesn't matter if the subreport uses @CurEffPer or @PCP_NPI passed from the main report or if the subreport uses default values for the parameters. The only time it gives the full list of members is when the query is run independently; when run by previewing the main report or the subreport, it loses the two names that are duplicated, even though the rest of the demographic data is different.</p>
  
  <p>What could be going on? The query works, but why is it not working in SSRS?</p>