473,467 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SQL Logic Help

I have been banging my head on this one for 2 days I might just need a
fresh set of eyes. This query lists all of the sales categories which
are listed in POSCat, more specifically POSCat.Description. It then
sums these categories as they appear in the sales history table
InvLine. What I like about this layout is that even if there is a null
sum value for a category it still will be listed and I can use
something like iif to make it $0.00.

Select POSCat.*,(Select Sum(InvLine.Price) From InvLine Where
POSCat.Description = InvLine.Cat) as Totals
FROM POSCat

The recordset looks like this

cat1 sumcat1
cat2 sumcat2

Now although that works on some levels its very limited and only gives
me a total for the table. What I really need is to verify that the
item has been paid for by comparing the invoice total to invoice paid,
also be able to search by date. What I came up with is this:

SELECT InvLine.Cat, SUM(InvLine.Price) AS Total
FROM Payments
INNER JOIN ((InvLine INNER JOIN Invoice ON Invoice.IId = InvLine.IId)
INNER JOIN PaySplit ON Invoice.IId = PaySplit.IId) ON Payments.PAYId =
PaySplit.PayId
WHERE Invoice.Total = Invoice.Paid AND Payments.PayDate BETWEEN
#1/2/03# AND #1/2/03#
GROUP BY InvLine.Cat
ORDER BY InvLine.Cat Asc

The recordset looks like this if there was values only in those
categories 1, 4, 5

cat1 sumcat1
cat4 sumcat4
cat5 sumcat5

Which works great except it only lists the categories which are not
null but I would like to list all of them like the first query does.

I am looking for help on how to merge the 2 queries together so that I
can list all categories but also search by date and make sure
Invoice.Total = Invoice.Paid

THanks in advance

Mar 21 '06 #1
10 1527
you can outer join the categories to the query in question so that all
the categories show up, regardless of whether they have related records
in your other query. Then you can format the null as zero using
NZ([SomeField])

Mar 22 '06 #2
Right ok I got a little bit of tunnel vision using the Inner Join, I am
kind of a newbie to this so how would you add the outer join to this
query. I'm sorry to be a pain but could you show me givin this query
how I could use a line like this, assuming that my example is what you
meant. See my problem is I need FROM Payments on my Inner Join then
POSCat on my outer how can I do both?
FROM POSCat LEFT OUTER JOIN ON POSCat.Description = InvLine.Cat
SELECT InvLine.Cat, SUM(InvLine.Price) AS Total
FROM Payments
INNER JOIN ((InvLine INNER JOIN Invoice ON Invoice.IId = InvLine.IId)
INNER JOIN PaySplit ON Invoice.IId = PaySplit.IId) ON Payments.PAYId =
PaySplit.PayId
WHERE Invoice.Total = Invoice.Paid AND Payments.PayDate BETWEEN
#1/2/03# AND #1/2/03#
GROUP BY InvLine.Cat
ORDER BY InvLine.Cat Asc

Mar 22 '06 #3
I tried this a few diffent ways but Access is complaining that the join
is not supported, so my SQL must be setup wrong. Here is what I have
so far, again any help is appreciated.

SELECT POSCat.Description, Sum(Payments.Value) AS Total
FROM POSCat LEFT OUTER JOIN (Payments INNER JOIN ((InvLine INNER JOIN
Invoice ON InvLine.IId = Invoice.IId) INNER JOIN PaySplit ON
Invoice.IId = PaySplit.IId) ON Payments.PAYId = PaySplit.PayId) ON
POSCat.Description = InvLine.Cat
WHERE (((Invoice.Total)=[Invoice].[Paid]) AND ((Payments.PayDate)
Between #3/20/2006# And #3/22/2006#))
GROUP BY POSCat.Description
ORDER BY POSCat.Description Asc

Mar 22 '06 #4
tranceport185 wrote:
I tried this a few diffent ways but Access is complaining that the join
is not supported, so my SQL must be setup wrong. Here is what I have
so far, again any help is appreciated.

SELECT POSCat.Description, Sum(Payments.Value) AS Total
FROM POSCat LEFT OUTER JOIN (Payments INNER JOIN ((InvLine INNER JOIN
Invoice ON InvLine.IId = Invoice.IId) INNER JOIN PaySplit ON
Invoice.IId = PaySplit.IId) ON Payments.PAYId = PaySplit.PayId) ON
POSCat.Description = InvLine.Cat
WHERE (((Invoice.Total)=[Invoice].[Paid]) AND ((Payments.PayDate)
Between #3/20/2006# And #3/22/2006#))
GROUP BY POSCat.Description
ORDER BY POSCat.Description Asc

What happens if you remove the word Outer?
Mar 22 '06 #5
Hi actually didn't try that but it gave me the same error its not that
it doesn't support the LEFT OUTER JOIN (well from what I have read at
least) its that it doesn't like the way I did it. But thanks for the
post.

Mar 22 '06 #6
"tranceport185" <sb*********@gmail.com> wrote in
news:11**********************@v46g2000cwv.googlegr oups.com:
I tried this a few diffent ways but Access is complaining that
the join is not supported, so my SQL must be setup wrong.
Here is what I have so far, again any help is appreciated.

SELECT POSCat.Description, Sum(Payments.Value) AS Total
FROM POSCat LEFT OUTER JOIN (Payments INNER JOIN ((InvLine
INNER JOIN Invoice ON InvLine.IId = Invoice.IId) INNER JOIN
PaySplit ON Invoice.IId = PaySplit.IId) ON Payments.PAYId =
PaySplit.PayId) ON POSCat.Description = InvLine.Cat
WHERE (((Invoice.Total)=[Invoice].[Paid]) AND
((Payments.PayDate) Between #3/20/2006# And #3/22/2006#))
GROUP BY POSCat.Description
ORDER BY POSCat.Description Asc


Does this work? (Outer join removed)

SELECT InvLine.Cat,
Sum(Payments.Value) AS Total
FROM (Payments
INNER JOIN (
(InvLine
INNER JOIN Invoice
ON InvLine.IId = Invoice.IId)
INNER JOIN PaySplit
ON Invoice.IId = PaySplit.IId)
ON Payments.PAYId = PaySplit.PayId)
WHERE (((Invoice.Total)=[Invoice].[Paid])
AND ((Payments.PayDate)
Between #3/20/2006# And #3/22/2006#))
GROUP BY InvLine.Cat
ORDER BY InvLine.Cat Asc

If it does, save that as a query and do the outer join in a
second query that calls the first. Access sometimes gets
confused with mixed join types.

--
Bob Quintal

PA is y I've altered my email address.
Mar 22 '06 #7
This is going to get interesting see my problem is the DB is part of a
closed system I cannot add or remove tables, queries, but I do have
permmisions to view/add/edit data. My hopes were to solve this using
pure SQL. I wonder if I could create a linked table in a second DB
with all of the info then create a query using linked tables, then
alter the SQL to use the linked tables ouch thats ugly. Any other ways
around this guys/gals?

PS that SQL is correct and thanks for the post

-Sam

Mar 22 '06 #8
tranceport185 wrote:
This is going to get interesting see my problem is the DB is part of a
closed system I cannot add or remove tables, queries, but I do have
permmisions to view/add/edit data. My hopes were to solve this using
pure SQL. I wonder if I could create a linked table in a second DB
with all of the info then create a query using linked tables, then
alter the SQL to use the linked tables ouch thats ugly. Any other ways
around this guys/gals?

PS that SQL is correct and thanks for the post

-Sam


I would try the linked table approach. The SQL works no differently.

--
Smartin
Mar 23 '06 #9
Yes your correct and everything seems to be working except I can't get
the date variables to pass from ASP

I have

strSQL = "SELECT POSCat.Description , InnerJoinCategoryReport.Total"_
& "FROM POSCat LEFT JOIN InnerJoinCategoryReport ON
InnerJoinCategoryReport.Cat = POSCat.Description "

which references saved query InnerJoinCategoryReport

SELECT InvLine.Cat, Sum(InvLine.Price) AS Total
FROM Payments INNER JOIN ((InvLine INNER JOIN Invoice ON
InvLine.IId=Invoice.IId) INNER JOIN PaySplit ON
Invoice.IId=PaySplit.IId) ON Payments.PAYId=PaySplit.PayId
WHERE (((Invoice.Total)=Invoice.Paid) And ((Payments.PayDate) Between
[dtStartDate] And [dtEndDate] ))
GROUP BY InvLine.Cat
ORDER BY InvLine.Cat;

If I run this in access it asks for the dates as it is setup
parameterized and will run. But how can I write the ASP because my
paramerized query is a sub query if this makes any sence!?! Any help
woul be great

Mar 23 '06 #10
"tranceport185" <sb*********@gmail.com> wrote in
news:11**********************@u72g2000cwu.googlegr oups.com:
Yes your correct and everything seems to be working except I
can't get the date variables to pass from ASP

I have

strSQL = "SELECT POSCat.Description ,
InnerJoinCategoryReport.Total"_
& "FROM POSCat LEFT JOIN InnerJoinCategoryReport ON
InnerJoinCategoryReport.Cat = POSCat.Description "

which references saved query InnerJoinCategoryReport

SELECT InvLine.Cat, Sum(InvLine.Price) AS Total
FROM Payments INNER JOIN ((InvLine INNER JOIN Invoice ON
InvLine.IId=Invoice.IId) INNER JOIN PaySplit ON
Invoice.IId=PaySplit.IId) ON Payments.PAYId=PaySplit.PayId
WHERE (((Invoice.Total)=Invoice.Paid) And ((Payments.PayDate)
Between [dtStartDate] And [dtEndDate] ))
GROUP BY InvLine.Cat
ORDER BY InvLine.Cat;

If I run this in access it asks for the dates as it is setup
parameterized and will run. But how can I write the ASP
because my paramerized query is a sub query if this makes any
sence!?! Any help woul be great

not sure what you are asking, but one trick I've done is to
create parameters in the parent query, then refer the sub-query
to those parameters. you may need to set up calculated fields
in the parent query to receive the parameters.

--
Bob Quintal

PA is y I've altered my email address.
Mar 23 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: nc | last post by:
My iterator can find my collection when my Action class calls my jsp directly, however when my Action class calls an html file that is set up with IFrames (one of which is loading that same jsp), I...
0
by: radha | last post by:
Hai all, My problem not just releated to sql. My problem is releated to good logic. I should not this type of questions hear. But just i am trying. If any body gave suggestions, or help i am...
5
by: Shabam | last post by:
I'm having a calendar feature developed whereby users can add recurring events. These recurring events can have start and end dates, meaning they will recur only within a date range. For...
2
by: Sam | last post by:
I'm working on a small application and I am stuck on the logic behind one of the queries I want to write. I've always considered myself to be a good problem solver and it depresses me that I can't...
7
by: Stephen | last post by:
I have some code which I call from a custom validator however I seem to have got the logic wrong and im having trouble figuring out how to write my code to get things to work the way I require....
24
by: cassetti | last post by:
Here's the issue: I have roughly 20 MS excel spreadsheets, each row contains a record. These records were hand entered by people in call centers. The problem is, there can and are duplicate...
14
by: rabbitrun | last post by:
Hi Everyone, I work for a financial company. I am planning to give a presentation to rest of the development team (15 people) here on moving server side logic to client-side javascript for an...
1
by: jonathan184 | last post by:
how to monitor and find out if files test1_* and test2_* files were sent in an hour and if not send an email This is on a unix system basically I got a cronjob that runs every sec polling a ftp dir...
9
by: SAL | last post by:
Hello, I have a Dataset that I have table adapters in I designed using the designer (DataLayer). I have a business logic layer that immulates the DataLayer which may/may not have additional logic...
15
by: bruno.desthuilliers | last post by:
On 27 juin, 18:09, "John Salerno" <johnj...@NOSPAMgmail.comwrote: For which definitions of "content" and "logic" ??? The point of mvc is to keep domain logic separated from presentation logic,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.