Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sub Query?
Message
De
03/03/2004 11:22:29
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Sub Query?
Divers
Thread ID:
00882748
Message ID:
00882748
Vues:
74
I have a table of month ending dates (monthdates), a table of assets (PK nassetid) and a transaction table (trans) which contains transactions for those assets and holds a FK to the asset table. I want to pull month ending dates for a given date range and at the same time find the max transaction date for a given assetid that is <= each monthend date I pull.

In English here is what I am trying to do:

SELECT all the monthending dates from the monthdates table where the monthendate is between a startdate and an enddate and for each of those resulting dates find the maximum tradedate from the transaction table where the tradedate <= each monthending date and the transaction assetid = a specific assetid

Example of what I would like the result set to look like:

monthenddate maxtradedate
1999-12-31 1999-12-26
2000-01-31 2000-01-15
2000-02-28 2000-02-02
2000-03-31 2000-02-02
2000-04-30 2000-04-05

Im having a hard time picturing the right way to formulate this query. Any suggestions?

Paul Montgomery
I can't complain but sometimes I still do - Joe Walsh
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform