473,414 Members | 1,697 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,414 software developers and data experts.

Finding Last Updated with a timestamp

Hi All

I know an SQL Server timestamp seems to be as useful as rocking horse for
show jumping, but I'm hoping you know a 'fudge' to get me round a problem or
at least confirm that it isn't possible.

I have 2 tables, one called ACCOUNTS and one called STOCK.

These tables have the usual ints, varchars, etc and have a timestamp field
as well.

My end user wants to see a simple list of the details in these tables
(individually - no joins present here), but sorted from most recently
updated to never touched.

As the timestamp seems to update each time a transaction hits it I though
this would be perfect, but I've had the following mixed results:

1) I did a simple ORDER BY TIMESTAMP DESC, but because the order is
alphanumeric I don't get a true 'recent to old' list.

2) So I did ORDER BY CAST(TIMESTAMP AS INT) DESC. There is a numeric sort
now, but the timestamp values seem to be hit and miss so that an account
that I know should be near the top is around about the middle.

Do you know how I can achieve the results I want?

Is the timestamp a waste of time?

Thanks

Robbie

Jul 20 '05 #1
2 10930
Hi

Timestamp is not a character field.. as stated in books online:

A nonnullable timestamp column is semantically equivalent to a binary(8)
column. A nullable timestamp column is semantically equivalent to a
varbinary(8) column.

When you select the column in QA, it will be displayed as a hexadecimal
number.

If you include DDL ( Create table statements etc... ) and example data (as
Insert statements) along with your query and the output, it may be clearer
what is occuring.

John
"Astra" <in**@NoEmail.com> wrote in message news:40**********@127.0.0.1...
Hi All

I know an SQL Server timestamp seems to be as useful as rocking horse for
show jumping, but I'm hoping you know a 'fudge' to get me round a problem or at least confirm that it isn't possible.

I have 2 tables, one called ACCOUNTS and one called STOCK.

These tables have the usual ints, varchars, etc and have a timestamp field
as well.

My end user wants to see a simple list of the details in these tables
(individually - no joins present here), but sorted from most recently
updated to never touched.

As the timestamp seems to update each time a transaction hits it I though
this would be perfect, but I've had the following mixed results:

1) I did a simple ORDER BY TIMESTAMP DESC, but because the order is
alphanumeric I don't get a true 'recent to old' list.

2) So I did ORDER BY CAST(TIMESTAMP AS INT) DESC. There is a numeric sort now, but the timestamp values seem to be hit and miss so that an account
that I know should be near the top is around about the middle.

Do you know how I can achieve the results I want?

Is the timestamp a waste of time?

Thanks

Robbie

Jul 20 '05 #2
Astra (in**@NoEmail.com) writes:
My end user wants to see a simple list of the details in these tables
(individually - no joins present here), but sorted from most recently
updated to never touched.

As the timestamp seems to update each time a transaction hits it I though
this would be perfect, but I've had the following mixed results:

1) I did a simple ORDER BY TIMESTAMP DESC, but because the order is
alphanumeric I don't get a true 'recent to old' list.

2) So I did ORDER BY CAST(TIMESTAMP AS INT) DESC. There is a numeric
sort now, but the timestamp values seem to be hit and miss so that an
account that I know should be near the top is around about the middle.


Since timestamp is 8 bytes and int only 4, a cast to int could lead to
funny things.

On the other hand, ORDER BY TIMESTAMP DESC will give you the rows in
some order that pertains to updates - and inserts. But it can be a bit
rough. Say that you at some point reloaded the table because of some
maintenance thing, that gave you new timestamp values.

So you are probably better off adding a "moddate" column, which you
update in case of "true" updates, either through stored procedures or a
trigger.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

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

Similar topics

0
by: zaceti | last post by:
I'm new to MySQL and I am having a problem selecting the highest valued date/time for a particular day. Here is the table structure: ...
4
by: Ike | last post by:
Is there a way in mysql to discern when the last date/time a field, row, or table was been updated or inserted? Thanks, ike
6
by: Ray | last post by:
Is there a simple way of selecting the last backup timestamp of a database from a table? Something like select last_backup_timestamp from tablename where database_name='WHATEVER' Or am I...
1
by: gnuoytr | last post by:
i can't find either confirmation or contradiction in the docs available. a colleague asserts that a column defined TIMESTAMP is always and automatically updated when any column in the row is...
4
by: vulcaned | last post by:
Hi All, Hopefully I explain this well........ In Access97 I have a form which has a tab control on it, each tab has a sub-form which is bound to its appropriate table(I'll call them 'Detail'...
3
by: Joe Kimbler | last post by:
I'm writing a "Hot Directory" software package that watches for an MP3 file to be uploaded to an FTP directory. When the file has completed uploading, it will be converted into a WAV file and...
1
by: Antony Paul | last post by:
Hi all, Is it possible to know when a row was last updated. Using 7.3.3. rgds Antony Paul ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading...
6
by: MLH | last post by:
I have a table - tblCorrespondence. It houses records of correspondence initiated here in our office. Records are appended whenever it is recognized that some type of outbound letter needs to be...
0
by: jaimebienlesfruits | last post by:
Is there a script I can include on the bottom of each page to indicate when the page was last updated? The PHP timstamp thing doesn't seem to work as it reflects the date of visit on the user's part....
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.