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
 General SQL Server Forums
 New to SQL Server Programming
 Replicating Last Function from Access in SQL

Author  Topic 

robtop
Starting Member

9 Posts

Posted - 2011-08-10 : 04:24:54
Morning,

I'm trying to replicate some of a database i built in Access into SQL but am a bit stuck as to how to replciate the Last function as it doen't seem to be supported in SQL server.

I have a list of values in a table callled 'Policy_Details' eg Policy Number, Name, Broker, Transaction Date.

The table is sorted by Transaction date, most recent at the bottom.

There could be multiple, different values of name for the same policy number so I want to select the name value associated with the most recent transaction in another view

In access this would be: LAST (Name) from Policy_Details

Unfortuantely this doesnt work in SQL Server.

I've seen the max function but am not entirely sure this does the same thing.

If anyone has any tips on how to do this correctly it woudl be much appreciated.

Thanks

Rob

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-10 : 07:28:57
the corresponding query in sql server would be

SELECT TOP 1 Name FROM Policy_Details ORDER BY [Transaction Date] DESC


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -