我有一个表格,用于维护应用程序中各种控件的输入时间和剩余时间。如果用户输入父控件,则输入的时间记录将插入到表中,并具有空的休假时间。如果用户随后在其中输入子控件,则父休假时间从 null 开始更新,并且为内部控件输入的时间将写入具有 null 剩余时间值的新记录中。在我们正在运行的应用程序的特定区域内花费的时间至关重要。问题是输入的时间是为内部控件记录的,因为在更新外部控件的剩余时间之前。维持时间的表是:
CREATE TABLE [dbo].[tTimeCapture](
[RECNUM] [int] IDENTITY(1,1) NOT NULL,
[Store_ID] [int] NULL,
[Tab_ID] [int] NULL,
[Dept_ID] [int] NULL,
[SubDept_ID] [int] NULL,
[Enter] [datetime] NULL,
[Leave] [datetime] NULL,
[IsStoreCall] [bit] NOT NULL,
[Upload] [int] NOT NULL,
CONSTRAINT [PK_tTimeCapture] PRIMARY KEY CLUSTERED
(
[RECNUM] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
此过程更新外部控制的离开时间并插入内部控制的记录:
if exists (
select
*
from
tTimeCapture
where
Leave is null
)
begin
exec sEndTimeCapture
end
INSERT INTO
tTimeCapture(
Store_ID,
Tab_ID,
Dept_ID,
SubDept_ID,
Enter,
Leave,
IsStoreCall,
Upload
)
SELECT
@Store_ID as Store_ID,
@Tab_ID as Tab_ID,
@Dept_ID as Dept_ID,
@Subdept_ID as SubDept_ID,
GETDATE() as Enter,
null as Leave,
@isStoreCall as IsStoreCall,
0 as Upload
sEndTimeCapture 过程如下:
update
tTimeCapture
set
Leave = getdate()
where
Leave is null
当进入外部控制时,第一个过程被称为插入一个具有空离开时间的新记录。离开外部控件并进入内部控件,proc 将外部控件的离开时间更新为第二个 proc 内的 getdate(),之后它为内部控件插入一条新记录,其休假值为空。每隔一段时间,内部控件的进入时间就会在外部控件的离开时间之前。怎么会这样?getdate() 精度有问题吗?外部控件的左侧时间为:2013-10-21 12:20:36.753,内部控件输入的时间为 2013-10-21 12:20:36.750