Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sub Query?
Message
 
 
To
03/03/2004 11:22:29
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Miscellaneous
Thread ID:
00882748
Message ID:
00882933
Views:
23
This message has been marked as the solution to the initial question of the thread.
Paul,

Try
SELECT monthenddate, 
  (SELECT MAX(tradedate) FROM trans tr
      where tr.assetid = @assetid 
        AND tr.tradedate <= med.monthenddate ) AS maxtradedate
  FROM monthdates med
>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
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform