473,386 Members | 1,997 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,386 software developers and data experts.

Cross-Tab Problem

** Admin Edit **
This thread has been split off from the original (Query/subquery - percentage).
** /Admin Edit **

Seeing as it appears we are coming to the end of this problem, i would like to present you with another one that perhaps will only take a little thought on your half.

Im creating a cross tab query which sorts via [SteveCode] and sums the [Tonnage] for each type of [RecyType]. I want to be able to add a date criteria, so the user can specify that the query processes data between two dates.

I have looked long and hard on the net for any answers and it seems that this has appeared often but without a proper solution. I offer the following SQL of my query:
Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [Forms]![Recycling Rates]![From Date] DateTime, [Forms]![Recycling Rates]![To Date] DateTime;
  2. TRANSFORM Sum(Tonnage.Tonnage) AS SumOfTonnage
  3. SELECT Tonnage.SteveCode
  4. FROM Tonnage
  5. WHERE (((Tonnage.SteveCode) Is Not Null) AND ((Tonnage.RecyType)="Dry (Recyclable)" Or (Tonnage.RecyType)="Green (Recyclable)" Or (Tonnage.RecyType)="Glass (Recyclable)" Or (Tonnage.RecyType)="Food (Recyclable)" Or (Tonnage.RecyType)="Residual") AND ((Tonnage.Date) Between [Forms]![Recycling Rates]![From Date] And [Forms]![Recycling Rates]![To Date]))
  6. GROUP BY Tonnage.SteveCode
  7. PIVOT Tonnage.RecyType;
If i change the two date parameters, the same results will show so it obviously is not working.

Any ideas?
Sep 12 '08 #1
10 1943
NeoPa
32,556 Expert Mod 16PB
Seeing as it appears we are coming to the end of this problem, i would like to present you with another one that perhaps will only take a little thought on your half.

Im creating a cross tab query which sorts via [SteveCode] and sums the [Tonnage] for each type of [RecyType]. I want to be able to add a date criteria, so the user can specify that the query processes data between two dates.

I have looked long and hard on the net for any answers and it seems that this has appeared often but without a proper solution. I offer the following SQL of my query:
Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [Forms]![Recycling Rates]![From Date] DateTime, [Forms]![Recycling Rates]![To Date] DateTime;
  2. TRANSFORM Sum(Tonnage.Tonnage) AS SumOfTonnage
  3. SELECT Tonnage.SteveCode
  4. FROM Tonnage
  5. WHERE (((Tonnage.SteveCode) Is Not Null) AND ((Tonnage.RecyType)="Dry (Recyclable)" Or (Tonnage.RecyType)="Green (Recyclable)" Or (Tonnage.RecyType)="Glass (Recyclable)" Or (Tonnage.RecyType)="Food (Recyclable)" Or (Tonnage.RecyType)="Residual") AND ((Tonnage.Date) Between [Forms]![Recycling Rates]![From Date] And [Forms]![Recycling Rates]![To Date]))
  6. GROUP BY Tonnage.SteveCode
  7. PIVOT Tonnage.RecyType;
If i change the two date parameters, the same results will show so it obviously is not working.

Any ideas?
I will have a quick stab at this, but if that doesn't resolve it, please post this as a separate question. You may post a link to your new thread in here if you will, but threads work a lot better if they stay on track.

Anyway, I think your ANDs and ORs might be the problem here. That is to say, I couldn't find an actual problem, but simplifying may help. Try this SQL anyway :
Expand|Select|Wrap|Line Numbers
  1. PARAMETERS [Forms]![Recycling Rates]![From Date] DateTime,
  2.            [Forms]![Recycling Rates]![To Date] DateTime;
  3.  
  4. TRANSFORM Sum(Tonnage) AS SumOfTonnage
  5.  
  6. SELECT SteveCode
  7.  
  8. FROM Tonnage
  9.  
  10. WHERE (([SteveCode] Is Not Null)
  11.   AND  ([RecyType] In('Dry (Recyclable)',
  12.                       'Green (Recyclable)',
  13.                       'Glass (Recyclable)',
  14.                       'Food (Recyclable)',
  15.                       'Residual'))
  16.   AND  ([Date] Between [Forms]![Recycling Rates]![From Date]
  17.                    And [Forms]![Recycling Rates]![To Date]))
  18.  
  19. GROUP BY SteveCode
  20.  
  21. PIVOT RecyType;
Sep 13 '08 #2
Last post then, if this doesnt solve then i will start a new thread.

Ive tried that SQL and there was a missing operator error message. my knowledge of SQL is very limited so i cannot solve this.
Sep 15 '08 #3
NeoPa
32,556 Expert Mod 16PB
My knowledge of Cross-Tab queries (PIVOT) is also limited, but if you post the whole error message then I'll see what I can do.

Posting a new thread might have garnered some new, more appropriate, expert interest.
Sep 15 '08 #4
Syntax error (missing operator) is query expression
(([SteveCode] Is Not Null)
AND ([RecyType] In('Dry (Recyclable)',
'Green (Recyclable)',
'Glass (Recyclable)',
'Food (Recyclable)',
'Residual')
AND ([Date]
Sep 15 '08 #5
NeoPa
32,556 Expert Mod 16PB
There should have been two ")"s after 'Residual' (My posted SQL was in error). You appreciate I'm not in a good position to test this, so I just have to be as careful as I can, working it out in my head.

I have now fixed this in post #3 so you can copy / paste it again and it should work.

Error messages can be quite helpful really ;)
Sep 15 '08 #6
brilliant. Right thats the last of that for me then. Just had to finish a few things off before i leave Friday for university and a completely different carrer path.

Thanks for your help.
Sep 16 '08 #7
NeoPa
32,556 Expert Mod 16PB
Very pleased that's working for you now.

For interest, which Uni are you off to and what are you studying?
Sep 16 '08 #8
NeoPa
32,556 Expert Mod 16PB
I've just come across a further two threads posted yesterday which both appear to have been asking the same question (as this). This is not acceptable (see the rules) as it wastes lots of time. I have removed them both.
Sep 16 '08 #9
aas4mis
97
There should have been two ")"s after 'Residual' (My posted SQL was in error). You appreciate I'm not in a good position to test this, so I just have to be as careful as I can, working it out in my head.

I have now fixed this in post #3 so you can copy / paste it again and it should work.

Error messages can be quite helpful really ;)
Stewart, just lookin out. Neo, Sorry, I couldn't resist. :P
"You just can't get the staff nowadays :D"
Sep 20 '08 #10
NeoPa
32,556 Expert Mod 16PB
:)

NB. The thread you are referring to is sum field twice in same query using different criteria.
Sep 20 '08 #11

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

Similar topics

0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
23
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
0
by: Web Science | last post by:
Site and Features: http://www.eigensearch.com Search engine, eigenMethod, eigenvector, mathematical, manifolds, science, technical, search tools, eigenmath, Jacobian, quantum, mechanics,...
3
by: jlamanna | last post by:
I was wondering if there was a utility that could tell you when your C# application is making cross-apartment COM calls. I have a fairly large application that makes extensive use of a 3rd party...
3
by: aspmonger | last post by:
Hello, I really believe that IE 6 has a new (intentional?) bug that severely limits the capability of dhtml and cross domain scripting. Yesterday, I read an interesting article about the subject and...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
7
by: Charles | last post by:
I'd like to develop a simple cross-platform application in C++. I'd like it to run in Windows, OS X, PC-BSD and Linux. From my research, it seems I should use Qt or Gtk as a graphical library. Do...
6
by: Bart Van der Donck | last post by:
Hello, I'm presenting my new library 'AJAX Cross Domain' - a javascript extension that allows to perform cross-domain AJAX requests. http://www.ajax-cross-domain.com/ Any comments or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...

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.