× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Art
You say - I need help with improving/simplifying this SQL statement:
What exactly are you trying to achieve?
Better readability?
Quicker response?

What may impriove the response (and I am really stressing MAY) is to use a Common Table Expression (CTE)
For example

New With extractf as
New (select * from dbslsdlg where dhdate >= 20150701 and dhdate <= 20150730)
SELECT substr(idept,1,1) as lineSeq, dpdesc, min(dhloc) as location, sum(dhsell*dhqty) + Sum(aSell * aQty) as Sales_Amt, sum(dhcost*dhqty) + Sum(aCost * aQty) as Cost_Amt,
(cast( ( sum(dhsell*dhqty) + Sum(aSell * aQty) ) - (sum(dhcost*dhqty) + Sum(aCost * aQty)) as double) / cast(sum(dhcost*dhqty) + Sum(aCost * aQty) as double)) as Margin
Removed
changed from extractf left join KCX340D.dbprodpf on dhino = ino
Left Join DBSLSDXL1 b on aINo = ino
Left join dbdeptpf on substr(idept,1,1) = deptno
where
aDate >= 20150701 and aDate <= 20150730
group by substr(idept,1,1), dpdesc order by 1, dpdesc;

I believe (but don't quote me on this) the joins are only done on the records you are interested in and not the entire file

Couple of things - hopefully someone will respond saying that my thoughts are correct
Hopefully, this is what you are looking for


Alan Shore
E-mail : ASHORE@xxxxxxxx
Phone [O] : (631) 200-5019
Phone [C] : (631) 880-8640
'If you're going through hell, keep going.'
Winston Churchill

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Art Duarte
Sent: Thursday, October 15, 2015 4:29 PM
To: Midrange Systems Technical Discussion
Subject: SQL Help

Hello,

I need help with improving/simplifying this SQL statement:

SELECT substr(idept,1,1) as lineSeq, dpdesc, min(dhloc) as location, sum(dhsell*dhqty) + Sum(aSell * aQty) as Sales_Amt, sum(dhcost*dhqty) + Sum(aCost * aQty) as Cost_Amt,
(cast( ( sum(dhsell*dhqty) + Sum(aSell * aQty) ) - (sum(dhcost*dhqty) + Sum(aCost * aQty)) as double) / cast(sum(dhcost*dhqty) + Sum(aCost * aQty) as double)) as Margin

from dbslsdlg left join KCX340D.dbprodpf on dhino = ino
Left Join DBSLSDXL1 b on aINo = ino
Left join dbdeptpf on substr(idept,1,1) = deptno
where dhdate >= 20150701 and dhdate <= 20150730
AND aDate >= 20150701 and aDate <= 20150730
group by substr(idept,1,1), dpdesc order by 1, dpdesc;

Appreciate your help!

Thank you
Art Duarte

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a moment to review the archives at http://archive.midrange.com/midrange-l.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.