title: How to avoid duplicate rows in my Scenario SQL Server?
body: <p>Here is my sql query and result. I got the result what I expect. But it's adding additional rows in my result.</p>
  
  <p>My query</p>
  
  <pre><code>Declare @store1001 varchar(10)='1001'
  Declare @storeAll varchar(10)='StoreAll'
  
  select ID,StoreID,TotalQtyParent into #tempQuantity
  From
  (
      select ID,@store1001 StoreID,Sum([TotalQtyParent]) TotalQtyParent
      FROM [HQMatajer].[dbo].[ItemRelationQty]
      where StoreID='1001' and TotalQtyParent is not null
      group by ID
  
      Union
  
      select ID,@storeAll StoreID,sum([TotalQtyParent]) TotalQtyParent
      FROM [HQMatajer].[dbo].[ItemRelationQty]
      where StoreID&lt;&gt;'1001' and TotalQtyParent is not null 
      group by ID
  ) totalquantity
  </code></pre>
  
  <p><strong>Above query result</strong>
  <a href="https://i.stack.imgur.com/6xCpA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6xCpA.png" alt="Result for above query"></a></p>
  
  <p><strong>OutPut Query</strong></p>
  
  <pre><code>  select TotalQty.ID, item.ItemLookupCode,item.Description,
      (
          case when TotalQty.StoreID = '1001' then TotalQty.TotalQtyParent
          else 0 end
      ) WHS,
      (
          case when TotalQty1.StoreID = 'StoreAll' then TotalQty1.TotalQtyParent
          else 0 end
      ) Store
  
  FROM
  #tempQuantity TotalQty
  INNER JOIN #tempQuantity TotalQty1 on TotalQty.ID=TotalQty1.ID
  LEFT JOIN HQMatajer.dbo.Item item on item.id=TotalQty.ID
  
  
  order by WHS desc,Store desc
  </code></pre>
  
  <p>Final Output</p>
  
  <p><a href="https://i.stack.imgur.com/fSpMw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fSpMw.png" alt="Final output"></a></p>
  
  <blockquote>
    <p>you can see the <strong>every second record of ID and the value of Store is Zero(0)</strong>. I don't want to show that row.</p>
    
    <p>Please don't suggest me to add the condition in where clause where store &lt;> 0. It's showing result because of my first query result,There every ID is two times are available. 
    Thanks</p>
    
    <p><strong>UPDATED</strong>
    I removed some columns from my output query to understanding purpose</p>
  </blockquote>