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
 SQL Server Development (2000)
 how to get last record in sql

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-08 : 09:39:27
dixi writes "im developing application using vb6 and database im using Ms. SQL Sever 2000. first im using ms access for database and no problem with it..

but when i export my database to SQL my application have error , the error is :

when im using sql statment for select last row (record) the application error

my sql statement is : "Select last(code) as Lcode from tblcust where code = '001' "

in Ms acces it's no problem but i got problem when im using SQL Server as database
the sql cannot detect "last" function

thank u for help me

best regard

pujan@hotmail.com"

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2002-05-08 : 09:44:57

SQL doesn't support the LAST keyword in aggregate queries like Access. Try this instead:

Select TOP 1 code as Lcode 
from tblcust
where code = '001'
ORDER BY Field1 desc

Field1 would probably be the identity column in your table. This should give the same results as Access.

Tim





Go to Top of Page

pu_jan
Starting Member

2 Posts

Posted - 2002-05-21 : 05:44:57
to sql team

thank u for u're attention
but when i try it, it doesn't work properly.

but when i change order by with group by it work
but i would like to say thank u..


my code now becom " select top 1 code, from tbl cust group by code"

best regard,
pujan



Go to Top of Page
   

- Advertisement -