We help IT Professionals succeed at work.

Pervasive 9 SQL Query

Citigirlgem
Citigirlgem asked
on
Medium Priority
204 Views
Last Modified: 2012-05-06
This query returns nothing in the Pervasive control centre, but works fine in Access based on the same Pervasive linked tables.  Why?

SELECT SALES_HISTORY_DETAIL.WHSE, SALES_HISTORY_DETAIL.CODE, Max(SALES_HISTORY_HEADER.IN_DATE) AS MaxOfIN_DATE
FROM SALES_HISTORY_HEADER INNER JOIN SALES_HISTORY_DETAIL ON SALES_HISTORY_HEADER.NUMBER = SALES_HISTORY_DETAIL.NUMBER
GROUP BY SALES_HISTORY_DETAIL.WHSE, SALES_HISTORY_DETAIL.CODE
having (((SALES_HISTORY_DETAIL.WHSE)<>'') AND ((SALES_HISTORY_DETAIL.CODE)<>''))

Open in new window

Comment
Watch Question

HAVING us used for applying filter criteria to field used in aggregates (ex. MAX).  You should use the standard WHERE clause.


SELECT SALES_HISTORY_DETAIL.WHSE, SALES_HISTORY_DETAIL.CODE, Max(SALES_HISTORY_HEADER.IN_DATE) AS MaxOfIN_DATE
FROM SALES_HISTORY_HEADER INNER JOIN SALES_HISTORY_DETAIL ON SALES_HISTORY_HEADER.NUMBER = SALES_HISTORY_DETAIL.NUMBER
WHERE (((SALES_HISTORY_DETAIL.WHSE)<>'') AND ((SALES_HISTORY_DETAIL.CODE)<>''))
GROUP BY SALES_HISTORY_DETAIL.WHSE, SALES_HISTORY_DETAIL.CODE

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
I tried that and it still gives me nothing.  Any other ideas?
What happens if you remove the WHERE clause?  

Author

Commented:
It still returns nothing.
Agreed about the WHERE rather than HAVING, try using IS NOT NULL rather than <> ''
Cheers, Andrew
SELECT SALES_HISTORY_DETAIL.WHSE, SALES_HISTORY_DETAIL.CODE, Max(SALES_HISTORY_HEADER.IN_DATE) AS MaxOfIN_DATE
FROM SALES_HISTORY_HEADER INNER JOIN SALES_HISTORY_DETAIL ON SALES_HISTORY_HEADER.NUMBER = SALES_HISTORY_DETAIL.NUMBER
WHERE SALES_HISTORY_DETAIL.WHSE IS NOT NULL AND SALES_HISTORY_DETAIL.CODE IS NOT NULL
GROUP BY SALES_HISTORY_DETAIL.WHSE, SALES_HISTORY_DETAIL.CODE

Open in new window

Author

Commented:
OK I figured it out. I needed and extra criteria in the where clause: "sales_history_Detail.RecNo>0".
Thanks anyway.

Author

Commented:
Thanks for the quick response.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.