473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Finding the most recient datetime


Hi,

My table has int Field1 and DateTime dtModificationTime. I maintain a
history of changes to the table by inserting a new record with a new
dtModificationTime. I need to be able to find the last inserted
record. It's easy to do Select * from table where field1=x ORDER BY
dtModificationTime. That works, but it hits all the records that
match the field. I need to come back with an exact hit. Can someone
point me in the right direction?

Thanks.

Sep 26 '05 #1
3 1318
Hi Johnny,

Use this

select top 1 * from table where field = X order by update_dt desc.

This would solve your problem.

Regards,
-Manoj Rajshekar

Sep 26 '05 #2
JohnnyRuin wrote:
Hi,

My table has int Field1 and DateTime dtModificationTime. I maintain a
history of changes to the table by inserting a new record with a new
dtModificationTime. I need to be able to find the last inserted
record. It's easy to do Select * from table where field1=x ORDER BY
dtModificationTime. That works, but it hits all the records that
match the field. I need to come back with an exact hit. Can someone
point me in the right direction?

Thanks.

See "Limiting Result Sets Using TOP and PERCENT", SET ROWCOUNT and
SELECT in Books Online:

select top 1 Field1, dtModificationTime
from dbo.MyTable
order by dtModificationTime desc

You should probably also consider what happens when you have multiple
rows with the same value in dtModificationTime.

Simon
Sep 26 '05 #3
Use the MAX function.

HTH

Jerry
"JohnnyRuin" <sc**********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...

Hi,

My table has int Field1 and DateTime dtModificationTime. I maintain a
history of changes to the table by inserting a new record with a new
dtModificationTime. I need to be able to find the last inserted
record. It's easy to do Select * from table where field1=x ORDER BY
dtModificationTime. That works, but it hits all the records that
match the field. I need to come back with an exact hit. Can someone
point me in the right direction?

Thanks.

Sep 27 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Aaron W. West | last post by:
Timings... sometimes there are almost too many ways to do the same thing. The only significant findings I see from all the below timings is: 1) Integer math is generally fastest, naturally....
3
by: mosdef_underground | last post by:
How can I use C# to find the most recently modified file in a folder? As you can probably guess, I am just a beginner, so any help would be appreciated. Thanks!
9
by: Laurent Bugnion | last post by:
Hi, I am wondering what is the best way to find out which ASP.NET sessions are still active. Here is the reason: I have a custom control which can upload files. It saves the files in a folder...
2
by: Thierry Lam | last post by:
Is there an easy way to determine the yesterday's date(year-month-day) from the python datetime library if I know today's date? Thanks Thierry
5
by: conckrish | last post by:
Hi all, Can anyone tell me how to find out the exact AGE from Date of Birth ( DateTime) in C#?? I have tried with DateTime.Now.Subtract(dob).But I coudlnt get the exact age.. Is there any...
6
by: krvrk | last post by:
Hi, I am creating a report for which i need to query a table for total number of users and Concurrent users logged in. The table will contain Username(nvarcar,not null),SessionStart...
10
by: kyosohma | last post by:
Hi, I am working on a timesheet application in which I need to to find the first pay period in a month that is entirely contained in that month to calculate vacation time. Below are some example...
0
by: rdraider | last post by:
I have an audit table that tracks changes to inventory items. I am trying to find the first change in avg_cost per item. The table will contain 1 row for the before record and another row for the...
7
by: Nick | last post by:
Hi there, I have a website that functions fine locally, but when published to the server it develops a bottleneck during loading some of the pages. Basically what happens is the page loads to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.