『逍遥』 - 2006-4-3 10:06:00
我用了两条语句:
1.delete from cars1 where 时间 < DATEADD(day,-3,getdate())
2.select * from cars1 where 时间 < DATEADD(day,-3,getdate())
为什么我都是用where 时间 < DATEADD(day,-3,getdate())当条件,但是结果相反呢?
DELETE删除的是大于的时间(相反了)
SELECT可正常。为什么呢?
使用SQL2000 SERVER
『逍遥』 - 2006-4-6 15:18:00
找到原因了。发上来大家看看。不过要谢谢各位网友了。
select * from cars1 where 时间 < CONVERT(DATETIME,DATEADD(day,-3,getdate()),121)
delete from cars1 where 时间 < CONVERT(DATETIME,DATEADD(day,-3,getdate()),121)
中秋月亮圆 - 2006-4-6 15:22:00
呵呵,都是高手。。。我还在C语言遨游呢。。
附件:
584329200646152232.gif
『逍遥』 - 2006-4-6 17:41:00
对了,上面的语句有的机子还是不行,改成这样了,把存储过程发上来。
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[DELCars1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[DELCars1]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE DELCars1
AS
DECLARE @Row1 smallint
BEGIN TRANSACTION
INSERT INTO CarsSer Select * from cars1 where datediff(day,时间,getdate())>=3
SET @Row1=@@rowcount
IF @@ERROR<>0
BEGIN
ROLLBACK TRANSACTION
RETURN 1
END
Delete from cars1 where datediff(day,时间,getdate())>=3
IF @@ERROR<>0 OR @@rowcount<>@Row1
BEGIN
ROLLBACK TRANSACTION
RETURN 1
END
COMMIT TRANSACTION
RETURN 0
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
© 2000 - 2026 Rising Corp. Ltd.