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
 Development Tools
 Other Development Tools
 How to query last record from the table?

Author  Topic 

smokeyfull
Starting Member

2 Posts

Posted - 2007-07-10 : 02:36:36
Hi All,

I have a MSDE database that stores meteorological parameters.
And I have a table named Meteo that stores paramaters like RecordTime, Air Temperature and Barometric Pressure.
This table is updated by dialing and pulling data from remote sites. That's working fine.

Now, I'm using ASP to connect to this database, retrieve the data and display it using Flash.
My question is :

1) How do I query the database to retrieve the last (latest) record (row) from this table?
Means here, for example, even if I don't dial and pull data from the remote site for the last 2 days, the query should return whatever last record that has been stored from the table and pass it to Flash for display.
I've done some searching on how to do this but what I found is that there is no concept of "order" of data stored in SQL Server. I read something about timestamp but I'm not sure how it works.
What I have now is that it displays the first record of the table but not the latest one.

Appreciate your help.

Thanks.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-10 : 02:38:57
[code]SELECT TOP 1 <column name list here>
FROM yourtable
ORDER BY RecordTime DESC[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

smokeyfull
Starting Member

2 Posts

Posted - 2007-07-11 : 23:22:41
quote:
Originally posted by khtan

SELECT TOP 1 <column name list here>
FROM yourtable
ORDER BY RecordTime DESC



KH
[spoiler]Time is always against us[/spoiler]





Thanks khtan...
Go to Top of Page
   

- Advertisement -