Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compare to previous record

Status
Not open for further replies.

shauns1

Programmer
Oct 21, 2005
53
AU
Hi

What is the correct way to compare a new record with the one before it. Basically, I have a table that stores web page names. Before adding another page name to the table, I want to check that the last one entered isn't the same page. If it is, the page name doesn't get entered again.

Is there a simple SQL trick for this?

Many thanks

Shaun
 
Can you set the page name to be a primary key?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hi, thanks for responding.

Not really because the same page name will appear multiple times - I just don't want it inserted twice in a row, oif that makes sense...
 
Oh, so you don't want it to appear if the previous row has had it entered? In that case you'll have to have a way of identifying what the last row actually is. Do you have a timestamp field that could be used to determine the latest row?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Timestamp is not advisable for this situation, as you may have several records with the same timestamp if you have a fast enough machine, and you would then be unable to know for sure which record was the last one added.



The only way I see for that then is to have the following

1- Sequence number (either autonumber or programatically created)

2- (Before) insert trigger

On this trigger you issue a select of the entry where the sequence number precedes the one you are adding. then compare required fields and abort insert if required.



Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Yes, exactly! I do have an autonumber field and that is exactly the question I am asking.

How do I make a Before Insert trigger and how do a find out what the preceeding number is?

Many thanks

Shaun
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top