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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 last unque inserted row

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-10-24 : 09:44:55
Eric writes "I need the follwing result


AutoInc , Position , Status
xxx , 1 , open
xxx , 2 , closed
xxx , 3 , faulty

from table

AutoInc , Position , Status , datetime
xxx , 1 , closed , 10/11/2005 20H20
xxx , 2 , closing, 10/11/2005 20H21
xxx , 3 , open , 10/11/2005 20H22
xxx , 1 , opening, 10/11/2005 20H23
xxx , 2 , faulty , 10/11/2005 20H24
xxx , 3 , open , 10/11/2005 20H25
xxx , 1 , opening, 10/11/2005 20H26
xxx , 2 , open , 10/11/2005 20H27
xxx , 3 , closed , 10/11/2005 20H28
xxx , 1 , open , 10/11/2005 20H29 <-- last changed status
xxx , 2 , closed , 10/11/2005 20H30 <-- last changed status
xxx , 3 , faulty , 10/11/2005 20H21 <-- last changed status
I tried various 'select' but my brains seems to be to small

greetings

Eric"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-24 : 10:17:26
There is no concept of First or Last record in SQL Server until you define it by Order by Clause

If you want to return last three records based on Date then

Select top 3 * from yourTable order by DateField Desc

If you want to return last three records based on Maximum Date on each Position refer point 2 here

http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspx



Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -