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

Crosstab Query and Specifying Selection Criteria

I have a basic crosstab queries that counts the models of each type of server device in a data center. What I'm trying to do is restrict the crosstab query from returning counts for devices that are less than a specifc number....say 100 for exampe.

So I want my query to display server models where there are 101 or more.

Here is SQL statement.

TRANSFORM Count(DEVICE_SPECS.DEVID) AS CountOfDEVID
SELECT DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE
FROM DEVICE_SPECS INNER JOIN (ACTIVE_GRID_LOCATIONS INNER JOIN Device ON ACTIVE_GRID_LOCATIONS.GRIDID = Device.GRIDID) ON DEVICE_SPECS.DEVID = Device.DEVID
WHERE (((ACTIVE_GRID_LOCATIONS.SITE_CODE)="12h" Or (ACTIVE_GRID_LOCATIONS.SITE_CODE)="9h") AND ((DEVICE_SPECS.MFR)="sun") AND ((Device.Disposition) Like "act*"))
GROUP BY DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE, Device.Disposition
PIVOT DEVICE_SPECS.[Equipment Type];

How can I do this? I can't place the condition on the Criteria line so I feel stuck and stumped.

Thanks in Advance,
-Frank
Mar 1 '07 #1
10 6092
MMcCarthy
14,534 Expert Mod 8TB
Frank

You can place it on the criteria as follow:

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(DEVICE_SPECS.DEVID) AS CountOfDEVID
  2. SELECT DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE
  3. FROM DEVICE_SPECS INNER JOIN (ACTIVE_GRID_LOCATIONS INNER JOIN Device 
  4. ON ACTIVE_GRID_LOCATIONS.GRIDID = Device.GRIDID) 
  5. ON DEVICE_SPECS.DEVID = Device.DEVID
  6. WHERE (((ACTIVE_GRID_LOCATIONS.SITE_CODE)="12h" 
  7. Or (ACTIVE_GRID_LOCATIONS.SITE_CODE)="9h") 
  8. AND ((DEVICE_SPECS.MFR)="sun") 
  9. AND ((Device.Disposition) Like "act*")) 
  10. AND Count(DEVICE_SPECS.DEVID) > 100
  11. GROUP BY DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE, Device.Disposition
  12. PIVOT DEVICE_SPECS.[Equipment Type];
  13.  
Mary
Mar 1 '07 #2
NeoPa
32,556 Expert Mod 16PB
Try that, and if it works as you want then simply ignore my post.
If not, try :
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(DEVICE_SPECS.DEVID) AS CountOfDEVID
  2. SELECT DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE
  3. FROM DEVICE_SPECS INNER JOIN (ACTIVE_GRID_LOCATIONS INNER JOIN Device 
  4. ON ACTIVE_GRID_LOCATIONS.GRIDID = Device.GRIDID) 
  5. ON DEVICE_SPECS.DEVID = Device.DEVID
  6. WHERE (((ACTIVE_GRID_LOCATIONS.SITE_CODE)="12h" 
  7. Or (ACTIVE_GRID_LOCATIONS.SITE_CODE)="9h") 
  8. AND ((DEVICE_SPECS.MFR)="sun") 
  9. AND ((Device.Disposition) Like "act*"))
  10. GROUP BY DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE, Device.Disposition
  11. HAVING Count(DEVICE_SPECS.DEVID) > 100
  12. PIVOT DEVICE_SPECS.[Equipment Type]
As the Count() results cannot be available when the incoming records are initially processed, this must be done in the HAVING clause which is processed AFTER the GROUP BY clause.
It can be put in the Criteria box as Mary says, but when translated to SQL it should end up in the HAVING clause if entered properly (I'm pretty sure).
Mar 5 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Try that, and if it works as you want then simply ignore my post.
If not, try :
Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(DEVICE_SPECS.DEVID) AS CountOfDEVID
  2. SELECT DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE
  3. FROM DEVICE_SPECS INNER JOIN (ACTIVE_GRID_LOCATIONS INNER JOIN Device 
  4. ON ACTIVE_GRID_LOCATIONS.GRIDID = Device.GRIDID) 
  5. ON DEVICE_SPECS.DEVID = Device.DEVID
  6. WHERE (((ACTIVE_GRID_LOCATIONS.SITE_CODE)="12h" 
  7. Or (ACTIVE_GRID_LOCATIONS.SITE_CODE)="9h") 
  8. AND ((DEVICE_SPECS.MFR)="sun") 
  9. AND ((Device.Disposition) Like "act*"))
  10. GROUP BY DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE, Device.Disposition
  11. HAVING Count(DEVICE_SPECS.DEVID) > 100
  12. PIVOT DEVICE_SPECS.[Equipment Type]
As the Count() results cannot be available when the incoming records are initially processed, this must be done in the HAVING clause which is processed AFTER the GROUP BY clause.
It can be put in the Criteria box as Mary says, but when translated to SQL it should end up in the HAVING clause if entered properly (I'm pretty sure).
I think you are right Ade (Everybody has to be at least once) :p
Mar 6 '07 #4
NeoPa
32,556 Expert Mod 16PB
So I make up for a couple of million of those poor souls who never managed it even the once then.
...and you're let off the hook :D
Mar 6 '07 #5
NeoPa,

When I copy your SQL statement over the existing SQL statements for the query I get a "Syntax error in TRANSFORM statement" reply.

Thanks,
-Frank
Mar 8 '07 #6
Mary,

Thanks very much for the assistance. When I copied your SQL statement over the existing statement, I got the following error.
Cannot have aggregate function in WHERE clause ((ACTIVE_GRID_LOCATIONS.SITE_CODE="12h" Or ACTIVE_GRID_LOCATIONS.SITE_CODE="9h") And DEVICE_SPECS.MFR="sun" And Device.Disposition Like "act*" And Count(DEVICE_SPECS.DEVID)>100).
Any suggestions?

Thanks,
-Frank

Frank

You can place it on the criteria as follow:

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(DEVICE_SPECS.DEVID) AS CountOfDEVID
  2. SELECT DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE
  3. FROM DEVICE_SPECS INNER JOIN (ACTIVE_GRID_LOCATIONS INNER JOIN Device 
  4. ON ACTIVE_GRID_LOCATIONS.GRIDID = Device.GRIDID) 
  5. ON DEVICE_SPECS.DEVID = Device.DEVID
  6. WHERE (((ACTIVE_GRID_LOCATIONS.SITE_CODE)="12h" 
  7. Or (ACTIVE_GRID_LOCATIONS.SITE_CODE)="9h") 
  8. AND ((DEVICE_SPECS.MFR)="sun") 
  9. AND ((Device.Disposition) Like "act*")) 
  10. AND Count(DEVICE_SPECS.DEVID) > 100
  11. GROUP BY DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE, Device.Disposition
  12. PIVOT DEVICE_SPECS.[Equipment Type];
  13.  
Mary
Mar 8 '07 #7
NeoPa
32,556 Expert Mod 16PB
NeoPa,

When I copy your SQL statement over the existing SQL statements for the query I get a "Syntax error in TRANSFORM statement" reply.

Thanks,
-Frank
I'll have to leave this one to Mary I'm afraid Frank.
My TRANSFORM skills are almost non-existent. I simply suggested a change to the original string in a more general area. Sorry.
Mar 9 '07 #8
MMcCarthy
14,534 Expert Mod 8TB
Try this ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. TRANSFORM Count(DEVICE_SPECS.DEVID) AS CountOfDEVID
  3. SELECT DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE
  4. FROM DEVICE_SPECS INNER JOIN (ACTIVE_GRID_LOCATIONS INNER JOIN Device 
  5. ON ACTIVE_GRID_LOCATIONS.GRIDID = Device.GRIDID) 
  6. ON DEVICE_SPECS.DEVID = Device.DEVID
  7. WHERE (((ACTIVE_GRID_LOCATIONS.SITE_CODE)="12h" 
  8. Or (ACTIVE_GRID_LOCATIONS.SITE_CODE)="9h") 
  9. AND ((DEVICE_SPECS.MFR)="sun") 
  10. AND ((Device.Disposition) Like "act*")) 
  11. GROUP BY DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE, Device.Disposition
  12. HAVING  Count(DEVICE_SPECS.DEVID) > 100
  13. PIVOT DEVICE_SPECS.[Equipment Type];
Mary
Mar 9 '07 #9
Mary,

Thanks again but now I'm getting the TRANSFORM error.

[quote]SYNTAX ERROR IN TRANSFORM STATEMENT

-Frank

Try this ...

Expand|Select|Wrap|Line Numbers
  1.  
  2. TRANSFORM Count(DEVICE_SPECS.DEVID) AS CountOfDEVID
  3. SELECT DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE
  4. FROM DEVICE_SPECS INNER JOIN (ACTIVE_GRID_LOCATIONS INNER JOIN Device 
  5. ON ACTIVE_GRID_LOCATIONS.GRIDID = Device.GRIDID) 
  6. ON DEVICE_SPECS.DEVID = Device.DEVID
  7. WHERE (((ACTIVE_GRID_LOCATIONS.SITE_CODE)="12h" 
  8. Or (ACTIVE_GRID_LOCATIONS.SITE_CODE)="9h") 
  9. AND ((DEVICE_SPECS.MFR)="sun") 
  10. AND ((Device.Disposition) Like "act*")) 
  11. GROUP BY DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE, Device.Disposition
  12. HAVING  Count(DEVICE_SPECS.DEVID) > 100
  13. PIVOT DEVICE_SPECS.[Equipment Type];
Mary
Mar 12 '07 #10
MMcCarthy
14,534 Expert Mod 8TB
Mary,

Thanks again but now I'm getting the TRANSFORM error.

SYNTAX ERROR IN TRANSFORM STATEMENT

-Frank
Try this ...

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(DEVICE_SPECS.DEVID) AS CountOfDevID
  2. SELECT DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE, Count(DEVICE_SPECS.DEVID) AS TotalOfDevID
  3. FROM (ACTIVE_GRID_LOCATIONS INNER JOIN Device 
  4. ON ACTIVE_GRID_LOCATIONS.GRIDID = Device.GRIDID) 
  5. INNER JOIN DEVICE_SPECS 
  6. ON Device.DEVID = DEVICE_SPECS.DEVID)
  7. WHERE ACTIVE_GRID_LOCATIONS.SITE_CODE IN ("9h", "12h")
  8. AND DEVICE_SPECS.MFR="sun" 
  9. AND Device.Disposition Like "act*"
  10. GROUP BY  DEVICE_SPECS.MFR, ACTIVE_GRID_LOCATIONS.SITE_CODE
  11. HAVING  Count(DEVICE_SPECS.DEVID) > 100
  12. PIVOT DEVICE_SPECS.[Equipment Type]; 
  13.  
Mar 12 '07 #11

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

Similar topics

3
by: Susan | last post by:
Can a textbox on a form be referenced as the criteria for a field in a crosstab query? When I use an expression like Forms!PFrmCriteria!Criteria, an error message appears saying Access can not...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
2
by: Sherman H. | last post by:
I have a few questions for crosstab and popup form questions: 1. I created a crosstab as follows: IT Financial Operation John 21 22 ...
4
by: Judy | last post by:
I'm using Access 2003 and was wondering if it is possible to have a paramater selection within a crosstab query so that I wouldn't need to build a new table. I have a select query that I'm using...
0
by: mtech1 | last post by:
Access 2002 I have a crosstab that is based on another query that references criteria from combo boxes on a form. I have defined the parameters in the crosstab and it works fine unless I use...
2
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
2
by: x | last post by:
hi i have made a crosstab query in which row heading is "date", colum heading is "aircraft type" and the value to be summed up is "1-10 row totals". i want to create a simple query which should...
14
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
14
ollyb303
by: ollyb303 | last post by:
Hi, I am trying to create a dynamic crosstab report which will display number of calls handled (I work for a call centre) per day grouped by supervisor. I have one crosstab query (Query1) which...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.