 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Larry Guest
|
Posted: Thu Jun 08, 2006 10:50 pm Post subject: Retrieving the last record entered. |
|
|
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
|
Posted: Thu Jun 08, 2006 11:13 pm Post subject: Re: Retrieving the last record entered. |
|
|
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
|
Posted: Thu Jun 08, 2006 11:16 pm Post subject: Re: Retrieving the last record entered. |
|
|
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
|
Posted: Fri Jun 09, 2006 12:38 am Post subject: Re: Retrieving the last record entered. |
|
|
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 |
|
 |
|
|
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
|
|