I have a temp table that contains duplicate groups. The groups are actually 2 tiered. For example, a group is a package with multiple products in that package. Below is a snippet showing a duplicate package. I indented the product to make it easier to read. Is there a way to only show one group? Maybe this is something easy and I'm just overthinking it. Any help would be greatly appreciated!!!
THANKS!!!
As a side note, i tried using distinct however it changed everything around. Like placing products above the package or in the wrong package. Basically distinct didn't seem to help.
Thanks for your reply! I tried your suggestion but had unexpected results which might be my fault as I wanted to simplify things. Ill go back to the start on this one
My original code to pull in the data into the temp table was:
select distinct nus.SvcID, nus.ParentSvcID, pc.svctypeid, pc.svcdesc, pc.charge
, case when producttype = 2 then 'Package' else 'Product' end as 'Type'
from tbl1 nus join tbl2 pc on nus.svctypeid = pc.svctypeid
group by nus.SvcID, nus.ParentSvcID, pc.svctypeid, pc.svcdesc, pc.charge, producttype
order by nus.SvcID, nus.ParentSvcID, pc.svctypeid, pc.svcdesc, pc.charge
As you can see, the SvcID is incremental which would render distinct useless (i think). You'll notice that the top tier package contains another package with the products underneath. This is one of the places I tried to simplify in my original example. I tried a number of things with the group by and order by but didn't have any luck so I decided to try inserting the data into a temp table and remove the svcID and Parent ID columns hoping that would help. This is why I had less columns in my original example.
I hope this helps and makes some sense. If not, ill provide whatever other information you need or clarification. I think Ive included everything in this post. Thoughts?
it appears that the ParentSvcID is NULL for the Highest tier Package, then the package contained within the orig package (if there is one) has its own ParentSvcID, and any Products below that are all the same ParentSvcID. So I'm guessing there has to be some group by or order by I'm not getting right. Ive moved things around in the group by and order by but haven't had any luck yet.