Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
rasmo2003
Starting Member
1 Post |
Posted - 2007-07-13 : 11:56:28
|
I'm trying to build a query to do the following, but as an intermediate SQL programmer, I have no idea how to do it.Datatable Foo_Log:LogID (primary key)FooID (foreign key)FooNameFooDescUpdateType (Possible values = 'insert', 'update', 'delete')UpdatedByUpdatedDateTimeFoo_Log is a log for the datatable Foo that records every insert, update, and delete that happens on Foo. Therefore, numerous records on Foo_Log could have the same FooID. What I need to get the something similar to the following pseudo-code:SELECT * FROM Foo_Log WHERE FooID IS DISTINCT AND UpdatedDateTime <= @DateTime AND (WHERE [the most recent record in Foo_Log WHERE FooID IS DISCTINCT AND UpdatedDateTime <= @DateTime] UpdateType <> 'delete') ORDER BY UpdatedDateTime DESCAnother why of saying it is: I want the most recent records for each unique parent id that are <= some date, but only if the most recent record does not have the updatetype of delete.If you have any ideas how to do this, your help would be much appreciated. |
|
|
|
|