Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 8378

Re: using 'while printing records'

$
0
0

To add to Jamie's option 1 above, a more "efficient" way to write the query would be something like this:

 

SELECT "OEIND94"."IDDOCD" AS INV_DATE,

             "OEIND94"."IDORD#" AS ORD_NUM,

             "OEIND94"."IDORDT" AS ORD_TYPE, 

             "OEIND94"."IDPRLC" AS PROD_FAMILY,

             "OEIND94"."IDPR$C" AS PRICE_CODE,

             "OEIND94"."IDCOM#",

             MAX("OEIND94"."IDPRT#") AS ITEM_REF,

             "ICPRT1"."IARCC4" AS PROD_TYPE,

             "ICPRT1"."IARC11" AS PROD_CLASS,

             "ICPRT1"."IACMQC" AS ***_CODE,

             SUM("OEIND94"."IDSHP#") AS NUM_UNITS,

             SUM("OEIND94"."IDSHP#" * "OEIND94"."IDCSU$") AS TOT_COST,

             SUM("OEIND94"."IDSHP#" * "OEIND94"."IDNTU$") AS TOT_SLS

             ,"ICPRT1"."IA101"

FROM   "SN4M"."ASTDTA"."OEIND94"

              "OEIND94" INNER JOIN "S1047N4M"."ASTDTA"."ICPRT1"

              "ICPRT1" ON "OEIND94"."IDPRT#"="ICPRT1"."IAPRT#"

        INNER JOIN (

          Select "totals"."IDORD#", sum("totals"."IDSHP#") as total_units

          from "SN4M"."ASTDTA"."OEIND94" "totals"

          where "totals"."IDCOM#" = '001' and

              "totals"."IDDOCD" >= {?FromDate} and

              "totals"."IDDOCD" <= {?ToDate}

          group by "totals"."IDORD#"

          having sum("totals"."IDSHP#") = 1

        ) as order_totals

        on "OEIND94"."IDORD#" = "order_totals"."IDORD#"

WHERE  "OEIND94"."IDCOM#"='001' AND 

                "OEIND94"."IDDOCD" >= {?FromDate} AND

                "OEIND94"."IDDOCD" <= {?ToDate} AND

              "ICPRT1"."IARCC4"='FIN'

GROUP BY "OEIND94"."IDDOCD",

                   "OEIND94"."IDORD#",

                    "OEIND94"."IDORDT",

                    "OEIND94"."IDPRLC",

                    "OEIND94"."IDPR$C",

                    "OEIND94"."IDCOM#",

                    "ICPRT1"."IARCC4" ,

                    "ICPRT1"."IARC11",

                    "ICPRT1"."IACMQC",

                    "ICPRT1"."IA101"

ORDER BY  "OEIND94"."IDDOCD",

                   "OEIND94"."IDORD#",

                    "OEIND94"."IDORDT",

                    "OEIND94"."IDPRLC",

                    "OEIND94"."IDCOM#"

 

The Select syntax in the "From" should get you the list of order ID's that have a total count equal to 1 - you'll only get one record for each order #.  By doing an inner join on this, you'll automatically filter out any orders that don't have a total count of 1.

 

-Dell


Viewing all articles
Browse latest Browse all 8378

Latest Images

Trending Articles



Latest Images