How Can I Get Lastest Value

Mar 14, 2008



I have a table for Units and Dollars based on 2 date keys ; snapshot date_key and delivery date_key (which are date key from date dimension)

This table do not update daily and if I want to have the information based on the lastest snapshot date_key how should I write a query for this case?

What I did was:





Code Snippet

SELECT snapshot_date_key,delivery_date_key, units, dollars
FROM dbo.tbl_fact
WHERE snapshot_date_key IN(SELECT DATE_KEY FROM tbl_DIM_Date
WHERE (FULL_DATE = DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))))





But this query is only available when snapshot date key exists in the table based on today.
If table is not updated today then I want to get the lastest snapshot_date_key from the fact table.
Max function with sanpshot_date_key does not work due to the delivery_date_key.

And kinds of advice would be greatly appreciated.
Thanks.

View 5 Replies


ADVERTISEMENT

How To Get Lastest Two Records For Each Cutstomer_number

Jun 5, 2006

Hi ,

My Requirment goes like this. In a table say X , i have two column called Customer_number and date_received. What i need to find is, lastest two enteries for the customer number. That is top 2 records for each customer_number.

the query out put is some thing like this,

Cust Number Date_received

1234 06/06/2005 10AM

1234 06/06/2005 08AM

1235 06/06/2005 10AM

1235 06/05/2005 10AM

1236 06/05/2005 11PM

1236 06/04/2005 06AM



How can i achieve the above functionality.

I hope i was clear in my explanation.



Regards,

Chetan

View 6 Replies View Related

Query To Select Lastest Record

May 30, 2012

If I selected the data below, how could I write a query to only keep the latest record. I added a "FileDate" column to label the last record (FileDate 200807)I want to display.

LeaseIDOpID Year MonthMCFFileDate
208801407982006 107660200807
208801407982006 107680200801
208801407982006 107784200704

View 5 Replies View Related

Return The Lastest [Identity] Field Value

Feb 17, 2004

Hi!

I have a question that might sound obvious to some of you but (obviously) not to me.

I have a stored procedure that adds a new record to a table that has an [Identity] field (TableID).

I want to return the value of the TableID of the newly created record. Sound simple ?

Thanks.

View 4 Replies View Related

Query To Pull Lastest Date Record

Apr 16, 2008

How do I pull only the latest shipdate record from a multiple record key?

I tried the following, but it doesn't pull only the lastest date record:

Select catnum, Max(shipdate) as shipdate from table_a group by catnum, shipdate

Thanks in advance.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved