There are two things here i want to accomplish.
这里有两件事我想完成。
-
List I want to pass a datetime into my stored procedure in the following format ('2007-05-28 00:00:00'), but that doesn't seem to work unless i use {ts '2007-05-28 00:00:00'}
列表我想以下列格式('2007-05-28 00:00:00')将日期时间传递到我的存储过程中,但这似乎不起作用,除非我使用{ts'2007-05-28 00 :00:00' }
-
The next thing is I want to increase the @SEAL_DATE by a second so it can be used to check the dates between the entered time and a second after.
接下来我想将@SEAL_DATE增加一秒钟,以便它可以用来检查输入时间和之后的第二天之间的日期。
Thanks in advance
提前致谢
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[getSealRecordDate] (@SEAL_DATE DATETIME)
AS
-- Declare variables
SELECT DISTINCT "FGFSTRANSFERS"."CONSIDERATION", "FGFSTRANSFERS"."AMOUNT_TRANSFER", "FGFSTRANSFERS"."DATE", "FGFSTransferDetails"."TRANSFER_ID", "FGFSTRANSFERS"."TRANSFER_ID", "FGFSTRANSFERS"."Curr", "FGFSTransferDetails"."CURR", "FGFSCUSTOMERS"."CMF_NAME_1", "FGFSCUSTOMERS"."CMF_NAME_2"
FROM ("FGFSInvestment"."dbo"."FGFSTransferDetails" "FGFSTransferDetails" INNER JOIN "FGFSInvestment"."dbo"."FGFSTRANSFERS" "FGFSTRANSFERS" ON "FGFSTransferDetails"."TRANSFER_ID"="FGFSTRANSFERS"."TRANSFER_ID") INNER JOIN "FGFSInvestment"."dbo"."FGFSCUSTOMERS" "FGFSCUSTOMERS" ON "FGFSTRANSFERS"."CUSTODIAN"="FGFSCUSTOMERS"."CMF_ACCOUNT"
WHERE ("FGFSTRANSFERS"."DATE">= @SEAL_DATE AND "FGFSTRANSFERS"."DATE"<{ts '2007-05-28 00:00:01'})
-- EXEC getSealRecordDate {ts '2007-05-28 00:00:00'}
Pseudo-SQL so it should be like: WHERE ("FGFSTRANSFERS"."DATE">= @SEAL_DATE AND "FGFSTRANSFERS"."DATE"< @SEAL_DATE+ 1 sec ) <-- Something like that
伪SQL所以它应该是:WHERE(“FGFSTRANSFERS”。“DATE”> = @SE_D_DATE和“FGFSTRANSFERS”。“DATE”<@ SEAL_DATE + 1秒)< - 类似的东西
3 个解决方案
#1
DATEADD(second, 1, @SEAL_DATE)
#2
Take a look How Does Between Work With Dates In SQL Server?
看一看如何在SQL Server中使用日期?
use dateadd to add a second
使用dateadd添加第二个
select dateadd(second,1,'20090625 00:00:00.000')
#3
For your second part, use DATEADD
对于第二部分,请使用DATEADD
DateAdd (second, 1, @DateVariable)
DateAdd(second,1,@ DateVariable)
#1
DATEADD(second, 1, @SEAL_DATE)
#2
Take a look How Does Between Work With Dates In SQL Server?
看一看如何在SQL Server中使用日期?
use dateadd to add a second
使用dateadd添加第二个
select dateadd(second,1,'20090625 00:00:00.000')
#3
For your second part, use DATEADD
对于第二部分,请使用DATEADD
DateAdd (second, 1, @DateVariable)
DateAdd(second,1,@ DateVariable)