BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Retrieving the last record entered.

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Larry
Guest





PostPosted: Thu Jun 08, 2006 10:50 pm    Post subject: Retrieving the last record entered. Reply with quote



CREATE TABLE [dbo].[InjectorRate] (
[TimeRecorded] [datetime] NULL ,
[InjectedRate] [smallmoney] NULL ,
[ShiftRate] [smallmoney] NULL ,
[WorkDate] [datetime] NULL ,
[Shift] [tinyint] NULL
) ON [PRIMARY]

When I run the following ...
Select InjectedRate, ShiftRate
From InjectorRate
Where TimeRecorded = (Select max(TimeRecorded)From InjectorRate)

it results in a table lock. All I want is the most recent record added. Is
there a better way?

DElphi 7

SQL 2003
Back to top
Jed Nicolau Filho
Guest





PostPosted: Thu Jun 08, 2006 11:13 pm    Post subject: Re: Retrieving the last record entered. Reply with quote



Hi Larry

Be careful when using max operator !
All table is locked as design if no index for this column is defined
but this behavior can change between different database systems.

Best Regards

Jed

"Larry" <lkillen (AT) charter (DOT) net> escreveu na mensagem
news:44886350$1 (AT) newsgroups (DOT) borland.com...
Quote:

CREATE TABLE [dbo].[InjectorRate] (
[TimeRecorded] [datetime] NULL ,
[InjectedRate] [smallmoney] NULL ,
[ShiftRate] [smallmoney] NULL ,
[WorkDate] [datetime] NULL ,
[Shift] [tinyint] NULL
) ON [PRIMARY]

When I run the following ...
Select InjectedRate, ShiftRate
From InjectorRate
Where TimeRecorded = (Select max(TimeRecorded)From InjectorRate)

it results in a table lock. All I want is the most recent record added.
Is
there a better way?

DElphi 7

SQL 2003

Back to top
Jed Nicolau Filho
Guest





PostPosted: Thu Jun 08, 2006 11:16 pm    Post subject: Re: Retrieving the last record entered. Reply with quote



Hi Larry

Create a column as Primary Key or a Datetime(with now in Insert event) then
the select statement is just : "select max(maycolumn) from table".

Best Regards

Jed

"Jed Nicolau Filho" <jed (AT) prouser (DOT) com.br> escreveu na mensagem
news:44886814 (AT) newsgroups (DOT) borland.com...
Quote:
Hi Larry

Be careful when using max operator !
All table is locked as design if no index for this column is defined
but this behavior can change between different database systems.

Best Regards

Jed

"Larry" <lkillen (AT) charter (DOT) net> escreveu na mensagem
news:44886350$1 (AT) newsgroups (DOT) borland.com...

CREATE TABLE [dbo].[InjectorRate] (
[TimeRecorded] [datetime] NULL ,
[InjectedRate] [smallmoney] NULL ,
[ShiftRate] [smallmoney] NULL ,
[WorkDate] [datetime] NULL ,
[Shift] [tinyint] NULL
) ON [PRIMARY]

When I run the following ...
Select InjectedRate, ShiftRate
From InjectorRate
Where TimeRecorded = (Select max(TimeRecorded)From InjectorRate)

it results in a table lock. All I want is the most recent record added.
Is
there a better way?

DElphi 7

SQL 2003



Back to top
Viatcheslav V. Vassiliev
Guest





PostPosted: Fri Jun 09, 2006 12:38 am    Post subject: Re: Retrieving the last record entered. Reply with quote

select top 1 InjectedRate, ShiftRate
from InjectorRate
order by TimeRecorded desc

Having PK on table would be good.

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)


"Larry" <lkillen (AT) charter (DOT) net> сообщил/сообщила в новостях следующее:
news:44886350$1 (AT) newsgroups (DOT) borland.com...
Quote:

CREATE TABLE [dbo].[InjectorRate] (
[TimeRecorded] [datetime] NULL ,
[InjectedRate] [smallmoney] NULL ,
[ShiftRate] [smallmoney] NULL ,
[WorkDate] [datetime] NULL ,
[Shift] [tinyint] NULL
) ON [PRIMARY]

When I run the following ...
Select InjectedRate, ShiftRate
From InjectorRate
Where TimeRecorded = (Select max(TimeRecorded)From InjectorRate)

it results in a table lock. All I want is the most recent record added.
Is there a better way?

DElphi 7

SQL 2003
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.