473,805 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ 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.Descript ion. 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.*,(Selec t Sum(InvLine.Pri ce) From InvLine Where
POSCat.Descript ion = 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.Pri ce) 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.PayDat e 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 1559
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.Descript ion = InvLine.Cat
SELECT InvLine.Cat, SUM(InvLine.Pri ce) 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.PayDat e 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.Descript ion, Sum(Payments.Va lue) 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.Descript ion = InvLine.Cat
WHERE (((Invoice.Tota l)=[Invoice].[Paid]) AND ((Payments.PayD ate)
Between #3/20/2006# And #3/22/2006#))
GROUP BY POSCat.Descript ion
ORDER BY POSCat.Descript ion 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.Descript ion, Sum(Payments.Va lue) 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.Descript ion = InvLine.Cat
WHERE (((Invoice.Tota l)=[Invoice].[Paid]) AND ((Payments.PayD ate)
Between #3/20/2006# And #3/22/2006#))
GROUP BY POSCat.Descript ion
ORDER BY POSCat.Descript ion 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
"tranceport 185" <sb*********@gm ail.com> wrote in
news:11******** **************@ v46g2000cwv.goo glegroups.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.Descript ion, Sum(Payments.Va lue) 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.Descript ion = InvLine.Cat
WHERE (((Invoice.Tota l)=[Invoice].[Paid]) AND
((Payments.PayD ate) Between #3/20/2006# And #3/22/2006#))
GROUP BY POSCat.Descript ion
ORDER BY POSCat.Descript ion Asc


Does this work? (Outer join removed)

SELECT InvLine.Cat,
Sum(Payments.Va lue) 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.Tota l)=[Invoice].[Paid])
AND ((Payments.PayD ate)
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.Descript ion , InnerJoinCatego ryReport.Total" _
& "FROM POSCat LEFT JOIN InnerJoinCatego ryReport ON
InnerJoinCatego ryReport.Cat = POSCat.Descript ion "

which references saved query InnerJoinCatego ryReport

SELECT InvLine.Cat, Sum(InvLine.Pri ce) AS Total
FROM Payments INNER JOIN ((InvLine INNER JOIN Invoice ON
InvLine.IId=Inv oice.IId) INNER JOIN PaySplit ON
Invoice.IId=Pay Split.IId) ON Payments.PAYId= PaySplit.PayId
WHERE (((Invoice.Tota l)=Invoice.Paid ) And ((Payments.PayD ate) 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

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

Similar topics

4
10314
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 get a servlet error "cannot find collection". Not usre if my issue is HTML, JSP, WebSphere or ??? Any help is very much appreciated. HTML file: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
0
1353
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 the lockest person that time. I just started working with sql server 3 Months back.
5
3896
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 instance, user A creates an event that recurs every Tuesday, from 1/1/05 - 3/2/06. The developer has decided that it would be good to have another table that stores each individual recurring event in a separate record. His logic is that this will help...
2
1539
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 figure this out. I don't really need any SQL syntax or anything, just help with ANDs, ORs, NOTs, etc... I have a table that has a column for a specific action. Each row in the table represents when an action is taken on a particular item. The...
7
2173
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. Below is the script I currently use and what it does along with what I would like it to do. Can someone please help me work how I can fix this. <script> function ValidateDropDownOrCheckBox(sender, args) { if ( document.forms.DropDownList1.value...
24
14420
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 phone numbers, and emails and addresses even person names. I need to sift through all this data (roughly 300,000+ records and use fuzzy logic to break it down, so that i have only unique records.
14
3571
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 internal intranet application rewrite. This approach will definitely stir up hot debate from hardcore server-side Java folks who wants to do UI stuff even on the server!. Since I am pretty much known as the JS or UI Guy of the group, my Boss...
1
1469
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 which name dir1 and transfers the file to another server So there are two types of files i want to check if are coming through and if they did not come through in an hour send an email. so files test1_* and test2_* I am checking for. Could...
9
2746
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 in. My business classes are, of course, decorated with the: <System.ComponentModel.DataObject() attribute. So, I drop a GridView on a webform and set its datasource to an ObjectDatasource which in turn is using one of my business logic...
15
2442
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, not to remove logic from presentation (which just couldn't work). Templating systems are for presentation logic. Whether they work by embedding an existing complete programmation language or by providing they're own specialised mini-language (or...
0
9716
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10360
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10105
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7646
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5542
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.