Solved

Pervasive SQL 9.5

Posted on 2011-02-16
5
1,234 Views
Last Modified: 2012-08-13
I am trying to include a subquery in Pervasive SQL 9.5 and I am getting syntax error.  Below is my query:

SELECT Price1.* FROM mhfspric AS Price1
WHERE PriceDate = 20110131
OR PriceDate =
(SELECT MAX(PriceDate) AS PriceDate FROM mhfspric
WHERE mhfspric.Cusip = Price1.Cusip
AND mhfspric.PriceDate <= 20101231
ORDER BY mhfspric.PriceDate DESC)
ORDER BY Cusip

This is what is returned by Pervasive Control Center:

<<<<<<<<<<<<<<<<<<<<<<<<
[Pervasive][ODBC Engine Interface]Syntax Error: SELECT * FROM mhfspric AS Price1
WHERE PriceDate = 20110131
OR PriceDate IN
(SELECT TOP 1 * FROM mhfspric
WHERE mhfspric.Cusip = Price1.Cusip
AND mhfspric.PriceDate <= 20101231
ORDER<< ??? >> BY
>>>>>>>>>>>>>>>>>>>>>>>>

Could I get assistance determining the correct syntax?
0
Comment
Question by:pwiginton
  • 3
  • 2
5 Comments
 
LVL 18

Expert Comment

by:mirtheil
Comment Utility
I'm confused.  In your statement you say you have:
OR PriceDate =
(SELECT MAX(PriceDate) AS PriceDate FROM mhfspric

but the error shows:

OR PriceDate IN
(SELECT TOP 1 * FROM mhfspric

Are you using the MAX or the TOP function?  
0
 

Author Comment

by:pwiginton
Comment Utility
I have tried both with the same results.
0
 

Author Comment

by:pwiginton
Comment Utility
I have a table of prices.  For example.

CUSIP PRICEDATE PRICE
11111 20110131 100.00
11111 20110115 99.83
11111 20110107 99.85
11111 20101231 85.00
11111 20101215 84.00
with records continuing back to 1992.

I what to get for all Cusips the 01/31 price and the most recent price 12/31 or older.
0
 
LVL 18

Accepted Solution

by:
mirtheil earned 250 total points
Comment Utility
According to the PSQL v9 docs, ORDER BY clauses are not supported in the subquery.  
0
 

Author Comment

by:pwiginton
Comment Utility
If I drop the ORDER BY from the subquery, use MAX(PRICEDATE) in the subquery, I should get the right results.  Is there a more efficient way to get the results I want?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now