scott_hanebutt
Starting Member
10 Posts |
Posted - 2009-06-05 : 15:04:57
|
I have a very complex sql query that works pefectly. I would however like to simplify it, speed it up, and increase my SQL knowledge. To that end I have coppied it below. Any suggestion on improvements would be greatly appreciated.-- LIST GENERIC PARTS THAT HAVE DIFFERENT PRICES THIS YEAR OR LAST YEAR-- IN THE PRICE SCHEDULER DEPENDING ON THE FINISH OPTIONSELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(FSCHECODE, '-3L','?'),'-4L','?'),'-25M','?'),'-25B','?'),'-25C','?'),'-2ML','?'),'-3ML','?') ,'-4ML','?'),'-5ML','?'),'-6LC','?'),'-7MC','?'),'-8DC','?'),'-2KL','?'),'-9BC','?') ,'-1NC','?'),'-2HC','?'),'?','-FINISH') AS GENERIC_PARTFROM INPRSCGROUP BY REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(FSCHECODE, '-3L','?'),'-4L','?'),'-25M','?'),'-25B','?'),'-25C','?'),'-2ML','?'),'-3ML','?') ,'-4ML','?'),'-5ML','?'),'-6LC','?'),'-7MC','?'),'-8DC','?'),'-2KL','?'),'-9BC','?') ,'-1NC','?'),'-2HC','?'),'?','-FINISH')HAVING MAX(FADJUST1) <> MIN(FADJUST1) -- ZONE1 CURRENT YEAR OR MAX(FADJUST2) <> MIN(FADJUST2) -- ZONE2 CURRENT YEAR OR MAX(FADJUST3) <> MIN(FADJUST3) -- ZONE1 LAST YEAR OR MAX(FADJUST4) <> MIN(FADJUST4) -- ZONE2 LAST YEARORDER BY GENERIC_PART |
|