Quantcast
Channel: SQL Server Reporting Services, Power View forum
Viewing all articles
Browse latest Browse all 10045

Help with Distinct or Grouping to get rid of duplicates

$
0
0

So Im stumped at the approach I need to take. have a query here:

select type_type,
        RCD_REASON,
        rc.description,
        MATERIAL_ID,
        USERID,
        DATETIME_SCRAPPED,
        ORDER_NUMBER,
        TRIMDATE,
        SUBSTR(SALES_ORDER,3,8)||'-'|| SUBSTR(SOL_LINE_NUMBER,3,4)AS SalesOrder,
        QTY,
        COMPONENT_MATERIAL_ID from WORKCELL.history hh innerjoin WORKCELL.reason_codes rcon hh.rcd_reason = rc.reasonwhere rc.type_type in('FAB','TRM')AND TO_CHAR(DATETIME_SCRAPPED,'YYYYMMDD')between to_char(:FromDate,'YYYYMMDD')AND to_char(:ToDate,'YYYYMMDD')orderby1,2,9

Thats pulling records based off two date parameters in SSRS. However, the problem is that I do not want duplicate records for MATERIAL_ID or ORDER_NUMBER. I realize I can't use Select Distinct for my current query because technically they are all distinct based off the DATETIME_SCRAPPED because it also includes the time. What would be the best way to organize this query to get all the rows I specified, and no duplicates based off the two columns?

Here is how I want the Data to look:

       QTY Fabric/Pc      Cut ForWhen                Prd Ord      Sched    Sales Ord     Name >1906700021-5F72 T500173 09/30/201407:36:370010388810842014092905594568-4170 rg >2906700021-5F72 T500173 09/30/201406:22:120010388810842014092905594568-4170 rg >2906700021-5F72 T500175 09/30/201402:04:070010388810522014092905594568-4210 rg >1906700021-5F72 T500175 09/30/201410:45:420010388810522014092905594568-4210 rg >1906700021-5F72 T500176 09/30/201407:13:450010388810572014092905594568-4240 rg

I would like it to only return this:

       QTY Fabric/Pc      Cut ForWhen                Prd Ord      Sched    Sales Ord     Name >1906700021-5F72 T500173 09/30/201407:36:370010388810842014092905594568-4170 rg >2906700021-5F72 T500175 09/30/201402:04:070010388810522014092905594568-4210 rg >1906700021-5F72 T500176 09/30/201407:13:450010388810572014092905594568-4240 rg

In the second data set, rows that have the same Prd Ord and Sales Ord, have been removed and the most recent time is used for the duplicate row.


Viewing all articles
Browse latest Browse all 10045

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>