Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New Problem

Status
Not open for further replies.

Reggie2004

Technical User
Oct 4, 2004
45
US
This is the code that I use to pull all the latest years from my query. The problem is that I cannot get my SSN P field to be included. Please help.



SELECT [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ]
FROM [Why not workable]
WHERE ((([Why not workable].TXPD)<>(SELECT MIN(TXPD) FROM [Why not workable])))
GROUP BY [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ], [Why not workable].[ DOD ]
HAVING (((Count([Why not workable].[SSN P ]))>1));



Thanks for all the help.



Reg
 
Your SSN P field is not listed in your SELECT statement as one of the fields to return. In fact, it's also missing from your GROUP BY statement.
 
When I add the field, like this...
SELECT [Why not workable].[SSN P ], [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ]
FROM [Why not workable]
WHERE ((([Why not workable].TXPD)<>(SELECT MIN(TXPD) FROM [Why not workable])))
GROUP BY [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ], [Why not workable].[ DOD ]
HAVING (((Count([Why not workable].[SSN P ]))>1));

I get the error You tried to execute a query that does not include the specified expression 'SSN P ' as part of an aggregate function.
 
Add 'SSN P ' to your GROUP BY clause

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 

SELECT [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ], [Why not workable].[ SSN P ], count(*)
FROM [Why not workable]
WHERE ((([Why not workable].TXPD)<>(SELECT MIN(TXPD) FROM [Why not workable])))
GROUP BY [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ], [Why not workable].[ SSN P ]
HAVING (Count(*) > 1;

 
This is the whole code and process.
1st I have this query that pulls all required information..

SELECT final.[SSN P ], final.TXPD, final.[LFRZ-RFRZ], final.[TC-150], final.[TC-290], final.[TC-291], final.[TC-300], final.[TC-301], final.[TC-420], final.[TC-421], final.[TC-424], final.[TC-530], final.[TC-540], final.[TC-590], final.[TC-591], final.[TC-594], final.[TC-599], final.[TC-976], final.[TC-977], final.[ DOB ], final.[ DOD ]
FROM final
WHERE (((final.[TC-290])="TC-290")) OR (((final.[TC-291])="TC-291") AND ((final.[ DOD ])="dead")) OR (((final.[TC-300])="TC-300")) OR (((final.[TC-301])="TC-301")) OR (((final.[TC-976])="TC-976")) OR (((final.[TC-977])="TC-977")) OR (((final.[TC-420])="TC-420")) OR (((final.[TC-421])="TC-421")) OR (((final.[TC-424])="TC-424")) OR (((final.[TC-150])="TC-150")) OR (((final.[TC-420])="TC-420")) OR (((final.[TC-421])="TC-421")) OR (((final.[TC-424])="TC-424")) OR (((final.[TC-530])="TC-530")) OR (((final.[TC-540])="TC-540")) OR (((final.[TC-590])="TC-590")) OR (((final.[TC-591])="TC-591")) OR (((final.[TC-594])="TC-594")) OR (((final.[TC-599])="TC-599"));

Next I query off this query to remove the first year.
SELECT [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ]
FROM [Why not workable]
WHERE ((([Why not workable].TXPD)<>(SELECT MIN(TXPD) FROM [Why not workable])))
GROUP BY [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ], [Why not workable].[ DOD ]
HAVING (((Count([Why not workable].[SSN P ]))>1));
This query gives me the desired results except I also need the SSN P field. When I add the SSN P field..
SELECT [Why not workable].[SSN P ], [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ]
FROM [Why not workable]
WHERE ((([Why not workable].TXPD)<>(SELECT MIN(TXPD) FROM [Why not workable])))
GROUP BY [Why not workable].[SSN P ], [Why not workable].TXPD, [Why not workable].[LFRZ-RFRZ], [Why not workable].[TC-150], [Why not workable].[TC-290], [Why not workable].[TC-291], [Why not workable].[TC-300], [Why not workable].[TC-301], [Why not workable].[TC-420], [Why not workable].[TC-421], [Why not workable].[TC-424], [Why not workable].[TC-530], [Why not workable].[TC-540], [Why not workable].[TC-590], [Why not workable].[TC-591], [Why not workable].[TC-594], [Why not workable].[TC-599], [Why not workable].[TC-976], [Why not workable].[TC-977], [Why not workable].[ DOB ], [Why not workable].[ DOD ], [Why not workable].[ DOD ]
HAVING (((Count([Why not workable].[SSN P ]))>1));

No data is returned. I hope this better explains my situation.

 
Have you tried running it with the requirement HAVING Count([SSN P ] > 0 ? See if you have any counts greater than 1. If you don't have any greater than 1, then no rows will be returned from the query as you have written it.

(By the way, to eliminate clutter and improve readability, I'd suggest that since you are only using one table you drop the table names preceeding each column, at least when posting here.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top