473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Multiple SUMS SQL Query

1
Large DB, It does a Primary sort- passing 350000 recs sorted. it thenn does a sum on one table, using a SELECT SUM, Then it reads a Secod time, using SLECT SUM, then it compares. It then goes back to the original recordset, gets the next record, and does the SUM's again. Could this be set up as a "NESTED" Loop?? or would a Stored PRc be better. Below are the 3 passes....of course it builds the string and passes...


Step # 1

SELECT Fee_Slip.Patient_No,last_name,first_name, Fee_Slip_items.update_dt, fee_slip_items.slipitm_no
FROM ((Fee_Slip INNER JOIN fee_slip_ITEMS ON fee_slip_items.feeslip_no = fee_slip.feeslip_no)

INNER JOIN Patient ON Fee_Slip.Patient_No = Patient.Patient_No)
WHERE feeslip_post = 1 AND patient.active=1 AND (patient.deceased is Null OR patient.deceased = 0) AND left(fee_slip_items.slipitm_prd_desc, 6) <> 'VOIDED'
ORDER BY patient.last_name, patient.first_name, Patient.Patient_No, fee_slip.feeslip_no



Step # 2

SELECT SUM(fee_slip_items.slipitm_pat_total) AS Total FROM fee_slip_items WHERE fee_slip_items.slipitm_no = 163371



Step # 3

SELECT Sum(Itmtrn_Amt) AS Total FROM Fee_Slip_Items_Trans WHERE fee_slip_items_trans.slipitm_no = 163371 AND ItmTrn_Pmt_Adj IN (0, 1)
Feb 3 '09 #1
1 2145
ck9663
2,878 Expert 2GB
You might be able to get away with the three queries by using CASE..WHEN..

-- CK
Feb 3 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Scott Cannon | last post by:
I am trying to query 3 tables all related by Clinet_ID. The Clients table, Monthly_Expenses table and Monthly_Income table. Each client can have 0>M instances of expenses, past due expenses, and...
1
by: Jeff Homan | last post by:
Hello all, I have a problem with a query in Access 97, and I'll try to give you all of the details to see if you have any idea if it's even possible: I have 2 tables: Inventory and Pricing ...
3
by: Beejer | last post by:
I'm currently having a hard time getting my expression to run in my billing query. My setup: MS Access 2003 Qry Billing (includes 6 tables such as Client, Price list, Formula, Order, Order...
27
by: spminba | last post by:
First, I want to say I have used this board to resolve many issues that I have had with access and I thank everyone who contributes. I have attempted to resolve my issue myself, but I am stumped and...
1
by: Mpho Pole | last post by:
Hi everyone.I'm a newly minted member, and I'm glad to be here. Now that the pleasanteries are out of the way, my problem is as follows: I have an SQL query which receives multiple parameters from...
1
by: psuaudi | last post by:
for example, i have 3 query levels...one bulids on the next. Query1 returns some results to query2, query2 returns some results to query3, then i want to use the query3 data. i would like to...
0
by: djflow | last post by:
Hi! II was wondering if you can help me with SQL query.. Below 7 separated select query works fine(only when they are retrieved separately) But I want to combined them together and so that i...
2
by: Leventcos21 | last post by:
Hi all, I have been stuck on this issue for weeks now and can not find a solution, so I hoping that someone can help me out. I am setting up a training database. I have setup the structure and...
1
by: santaferubber | last post by:
The first query returns me the results from multiple databases, the second does the same thing except it puts the result into a #temp table? Could someone please show me an example of this using...
0
by: Jeff Miller | last post by:
(No code of any sort follows) Scenario: Need to generate an annual performance report for any given employee. Personnel are keyed by an employee number (#) Two tables each which handle two...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.