TSQL to SELECT dimDate that are less than or equal to last factTable date

  • I would like to SELECT only dates from my dimDate table that are less than or equal to the latest date in my factTable. Any syntax for this would be greatly appreciated.

  • joeshu26 (12/31/2015)


    I would like to SELECT only dates from my dimDate table that are less than or equal to the latest date in my factTable. Any syntax for this would be greatly appreciated.

    This will return a distinct result of dates which are equal to or less than the most recent sales transaction date.

    SELECT FullDate

    FROM DimDate

    WHERE DateKey <= (SELECT MAX(SaleDateKey) FROM FactSales);

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

  • joeshu26 (12/31/2015)


    I would like to SELECT only dates from my dimDate table that are less than or equal to the latest date in my factTable. Any syntax for this would be greatly appreciated.

    You could select the MAX(date) from your fact table and store it in a variable. You can then use that in WHERE clause, or JOIN statement, of the query where you use the dimDate table.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • This worked great Thank you!

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply