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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL syntax 1

Status
Not open for further replies.

GrigoreDolghin

Programmer
Oct 23, 2000
167
RO
Hello

Background info:

A historical stock table. It contains the following fields:

ArticleId Stock Date
Article1 50 01/31/2002
Article2 100 01/31/2002
Article1 75 02/28/2002
Article2 120 02/28/2002
Article1 90 03/31/2002
Article2 130 03/31/2002

Question:
I need to enter a datetime variable and to get the articles having date the greatest date lower than the date entered. For example, if I enter 23/03/2002, I should have the articles with 01/31/2002; if I enter 12/31/2002 I should have the articles with 03/31/2002, and so on.

Is there a way to accomplish that?

Thank you. Grigore Dolghin
Class Software
Bucharest, Romania
 
Try this

select articleid, stock from articles
where date in
(select max(date) from articles a2
where a2.articleid = articleid and
a2.date < '2002-03-23')
 
Thank you. I did write a similar syntax, but, somehow, I screwed it up, because I didn't get what I wanted. Now it's all clear.
Grigore Dolghin
Class Software
Bucharest, Romania
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top