473,661 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Complex query question

I have a table with a "Status" column (lookup field to the status
table) and an "Escalation ID" column (which may or may not be filled
in). I want a report that indicates complete or not for 2 categories:
"Escalation " and "Other".

Row headers should be "Escalation " (EscalationID = not null) and
"Other" (EscalationID = null).

Column headers should be "Complete" (Status = "Complete") ,
"Incomplete " (Status <> "Complete") and "Total" (count all).

It's a crosstab query, but I don't know how to make a crosstab sort by
"null or not" and "complete or not" instead of just values.

Any help will be greatly appreciated. Thanks!

Keith
Nov 12 '05 #1
7 1366
In the Field row of the query, enter:
(EscalationID Is Null)
in one column, and in the next:
(Status <> "Complete")

This will generate a pair of fields containing true or false.
You should be able to generate the crosstab from there.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Keith Work" <wk****@moviela nd.com> wrote in message
news:4a******** *************** ***@posting.goo gle.com...
I have a table with a "Status" column (lookup field to the status
table) and an "Escalation ID" column (which may or may not be filled
in). I want a report that indicates complete or not for 2 categories:
"Escalation " and "Other".

Row headers should be "Escalation " (EscalationID = not null) and
"Other" (EscalationID = null).

Column headers should be "Complete" (Status = "Complete") ,
"Incomplete " (Status <> "Complete") and "Total" (count all).

It's a crosstab query, but I don't know how to make a crosstab sort by
"null or not" and "complete or not" instead of just values.

Any help will be greatly appreciated. Thanks!

Keith

Nov 12 '05 #2
"Keith Work" <wk****@moviela nd.com> wrote in message
news:4a******** *************** ***@posting.goo gle.com...
I have a table with a "Status" column (lookup field to the status
table) and an "Escalation ID" column (which may or may not be filled
in). I want a report that indicates complete or not for 2 categories:
"Escalation " and "Other".

Row headers should be "Escalation " (EscalationID = not null) and
"Other" (EscalationID = null).

Column headers should be "Complete" (Status = "Complete") ,
"Incomplete " (Status <> "Complete") and "Total" (count all).

It's a crosstab query, but I don't know how to make a crosstab sort by
"null or not" and "complete or not" instead of just values.

you could do it with subqueries, but it will probably be slow

select nz(k.Escalation ID, "Other") AS escalation,
(
select count(*) from keith k2
where k2.Status = "Complete"
and k2.EscalationID = k.EscalationID
) as complete,
(
select count(*) from keith k2
where k2.Status <>"Complete"
and k2.EscalationID = k.EscalationID
) as incomplete,
(
select count(*) from keith k2
where k2.EscalationID = k.EscalationID
) as total
from keith as k
group by k.EscalationID
A better might be to use a derived table to calculate the complete status of
each row as an integer, 1 or zero, and then sum them up.

select A.escalation, sum(A.complete) as complete,
count(*) - sum(A.complete) as incomplete,
count(*) AS total
from
(
select nz(EscalationID ,"Other") as escalation,
IIf(Status="Com plete",1,0) as complete
from keith
) AS A
group by A.escalation

These aren't tested. If you need any more help please post some sample data
with the output you require.




Nov 12 '05 #3

Haven't had a chance to try it yet (I will tomorrow), but here's the data
and results I need. I'm converting some job-aids from various sources into a
common tool and need to provide reporting to the managers through the whole
process:

Sample data:

RecordNumber Description Status EscalationID
123 Job aid to do A... Pending 321
234 Job aid to do B... Rewrite 432
345 Job aid to do C... Complete
456 Job aid to do D... Complete 543
567 Job aid to do E... Deleted

I need returned a table that reads thusly:

Complete Incomplete Total
Escalation 1 2 3
Other 1 1 2
Total 2 3 5

Hopefully the formatting doesn't get hosed too badly. Thanks. :)

Keith
"John Winterbottom" <as******@hotma il.com> wrote in message
news:2g******** ****@uni-berlin.de...
"Keith Work" <wk****@moviela nd.com> wrote in message
news:4a******** *************** ***@posting.goo gle.com...
I have a table with a "Status" column (lookup field to the status
table) and an "Escalation ID" column (which may or may not be filled
in). I want a report that indicates complete or not for 2 categories:
"Escalation " and "Other".

Row headers should be "Escalation " (EscalationID = not null) and
"Other" (EscalationID = null).

Column headers should be "Complete" (Status = "Complete") ,
"Incomplete " (Status <> "Complete") and "Total" (count all).

It's a crosstab query, but I don't know how to make a crosstab sort by
"null or not" and "complete or not" instead of just values.
you could do it with subqueries, but it will probably be slow

select nz(k.Escalation ID, "Other") AS escalation,
(
select count(*) from keith k2
where k2.Status = "Complete"
and k2.EscalationID = k.EscalationID
) as complete,
(
select count(*) from keith k2
where k2.Status <>"Complete"
and k2.EscalationID = k.EscalationID
) as incomplete,
(
select count(*) from keith k2
where k2.EscalationID = k.EscalationID
) as total
from keith as k
group by k.EscalationID
A better might be to use a derived table to calculate the complete status

of each row as an integer, 1 or zero, and then sum them up.

select A.escalation, sum(A.complete) as complete,
count(*) - sum(A.complete) as incomplete,
count(*) AS total
from
(
select nz(EscalationID ,"Other") as escalation,
IIf(Status="Com plete",1,0) as complete
from keith
) AS A
group by A.escalation

These aren't tested. If you need any more help please post some sample data with the output you require.



Nov 12 '05 #4
"Keith Work" <no@spam> wrote in message
news:L7******** ************@co mcast.com...

Haven't had a chance to try it yet (I will tomorrow), but here's the data
and results I need. I'm converting some job-aids from various sources into a common tool and need to provide reporting to the managers through the whole process:

Sample data:

RecordNumber Description Status EscalationID
123 Job aid to do A... Pending 321
234 Job aid to do B... Rewrite 432
345 Job aid to do C... Complete
456 Job aid to do D... Complete 543
567 Job aid to do E... Deleted

I need returned a table that reads thusly:

Complete Incomplete Total
Escalation 1 2 3
Other 1 1 2
Total 2 3 5

this looks ugly but it should work and performance shouldn't be too bad:

select escalation, Incomplete, Complete, Total
from
(
select escalation, sum(c) as complete,
count(*) - sum(c) as Incomplete,
count(*) as total, 0 as sort
from
(
select IIf(EscalationI D is not null,"Escalatio n", "Other")
as escalation,
IIf(Status="Com plete",1,0) as c
from keith
) as A
group by escalation
union all
select "Total", sum(c), count(*)-sum(c), count(*), 1
from
(
select IIf(Status="Com plete",1,0) as c
from keith
) as A
) as B
order by sort




Nov 12 '05 #5
Thanks John. I plugged it into my database and replaced "keith" with
the table name but I get a "syntax error in FROM clause". Access also
keeps replacing the first and last parenthesis in the whole statement
with brackets []. I can save it with the brackets, but it asks me what
"escalation " is when I run it.

Sorry I can't help more. I can make sense out of a statement written
but just don't know SQL well enough to troubleshoot it myself. Thanks
again.

Keith

"John Winterbottom" <as******@hotma il.com> wrote in message news:<2g******* *****@uni-berlin.de>...

this looks ugly but it should work and performance shouldn't be too bad:

select escalation, Incomplete, Complete, Total
from
(
select escalation, sum(c) as complete,
count(*) - sum(c) as Incomplete,
count(*) as total, 0 as sort
from
(
select IIf(EscalationI D is not null,"Escalatio n", "Other")
as escalation,
IIf(Status="Com plete",1,0) as c
from keith
) as A
group by escalation
union all
select "Total", sum(c), count(*)-sum(c), count(*), 1
from
(
select IIf(Status="Com plete",1,0) as c
from keith
) as A
) as B
order by sort

Nov 12 '05 #6
"Keith Work" <wk****@moviela nd.com> wrote in message
news:4a******** *************** **@posting.goog le.com...
Thanks John. I plugged it into my database and replaced "keith" with
the table name but I get a "syntax error in FROM clause". Access also
keeps replacing the first and last parenthesis in the whole statement
with brackets []. I can save it with the brackets, but it asks me what
"escalation " is when I run it.

Sorry I can't help more. I can make sense out of a statement written
but just don't know SQL well enough to troubleshoot it myself. Thanks
again.

What version of Access are you running? I tested this with Access 2003 but
it should work all the way back to Access 2000. If you're still using 97
then we need to modify it slightly - let me know.
Nov 12 '05 #7
Found the problem. I had one of our in-house guys take a look and he
found the problem. We changed EscalationsID to [Escalations ID] (the
correct field name - doh!) and that did it.

Excellent code there. Thanks a LOT!

Keith
Nov 12 '05 #8

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

Similar topics

1
3441
by: Paul Bramscher | last post by:
Here's one for pathological SQL programmers. I've got a table of things called elements. They're components, sort of like amino acids, which come together to form complex web pages -- as nodes in trees which form parent-child relationships, sort of like newsgroups. For example, the parent_id field points to another element. Indent_level is there for denormalization purposes, to avoid costly recursive issues in querying. The...
4
8965
by: Starbuck | last post by:
OK, first let me say that I am no DB person. But I have a user here who keeps getting this error whenever she does, whatever it is she does, with databases... A google search takes me to various forums where I am forced to sign up before I can read any answers. Interesting note here is that the guy in the office next
2
6070
by: Mikel | last post by:
I am trying to get around the problem "The expression you have entered is too complex" for a select query. (The example below is not the expression that is giving me headaches.) So I am thinking that I just need to do the parsing and calculating in an event procedure for an "On Click" event. My question is: If I have a query field in access97 that parses date (in format
1
1142
by: Giloosh | last post by:
hello, i dont know if what i want to do is really considered complex, but i sure cannot figure it out. i need to create a query that shows the payments a person makes every day for a variable date range. for THIS example the date range is 5/1/2004 - 5/4/2004 (day1-day4) The original table has 3 feilds :ID, DATE, PAYMENT ID\ DATE \ PAYMENT
8
5058
by: Matt | last post by:
Hi all, Thank you for taking the time. I have a database with 45 tables on it. 44 tables are linked to a main table through a one to one relationship. My question is, is there no way i can have a query that will pull a single field from all the tables. In other words i should have 44 fields. when i try to do that same, i get an error message saying "Query is too complex"
0
2206
by: schan | last post by:
Hi there, I was wondering if someone could shed some light on a problem I have no idea on how to fix. I created an Excel Add-In that uses an ADO connection to an Access database on a file server, which in turn has its tables linked to an Oracle back-end. I'm pretty sure I can take out Access as the middleman by just querying against the Oracle database, but that's not my question.
6
1714
by: pippapippa | last post by:
I should be most grateful for a little advice. I have used Access 2000 & latterly 2002. Am about to upgrade since it is evident that documentation, tutorials etc are more readily available in later versions. I work on this on my lonesome & do not have access to a mentor or tuition. This is an intermittent activity and quite adjunct to my "normal" investment activities. I have found that most books & documentation are either...
13
2302
by: DDonnachie | last post by:
Hi folks, The following SQL statment works SELECT StaffHoursTable.EngName, StaffHoursTable.JobNumberShadow, ++++++ AS Norm_Hours, ++++++ AS OT_Hours, wktodate(StaffHoursTable.WeekNo,StaffHoursTable.Year) AS WeekDate, Jobs.ProjectType, Jobs.ProjectDescription, wktodate(.,.) FROM (StaffHoursTable INNER JOIN Jobs ON StaffHoursTable.JobNumberShadow = Jobs.JobNumber) INNER JOIN EngStaff ON StaffHoursTable.EngName = EngStaff.Eng_Staff ...
3
1488
by: BUmed | last post by:
Ok let me start from the start. I have a form that has question in it and the person chooses 0 1 2 -99 for each. The form then needs to add up the numbers for the sub categories in the form. For example question 1-8 deal with communication and can rang from 0 to 16 points. The problem that I'm running into is the -99 which is needed to denote that the question does not ably. So if one of the communication questions is NA then it will make the...
0
2444
crystal2005
by: crystal2005 | last post by:
Hi, I am having trouble with some complex SQL queries. I’ve got winestore database, taken from Web Database Application with PHP and MySQL book. And some question about queries as the following 1. The wine name, grape variety, year, winery, and region 2. The minimum cost of wine in the inventory 3. The number of bottles available at the minimum price 4. The total number of bottles available at any price 5. The total number of unique...
0
8432
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
8343
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
8758
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
8545
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
8633
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...
0
7364
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4179
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...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1743
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.