I would like to use the LAST function in SQL Server, but I read it will not work. It does in MS ACCESS though. Does anybody know the function to use which is similar to LAST?
Thanks
FalseDawn
8:49 pm on Dec 9, 2005 (gmt 0)
If your table has an IDENTITY column (say, my_id), you can do something like
SELECT fieldname FROM yourtable WHERE my_id=(SELECT MAX(my_id) FROM yourtable)
Or, if you need the last value immediately after an INSERT, you could use the @@IDENTITY global variable.
aspdaddy
4:21 pm on Dec 10, 2005 (gmt 0)
The problem with relational databases is theres no order of rows so theres no first or last. In SQL you can use the Max function, you can write a function or use scope_identity to get the most recently created record.