Sql 声明日期转换错误

Sql 声明日期转换错误,sql,datetime,declare,Sql,Datetime,Declare,我不确定这里出了什么问题,但有人能帮我吗。我不熟悉在SQL中声明日期时间 declare @START datetime2 = '2013-07-17 00:00:00.00'; declare @END datetime2 = '2013-07-17 23:59:99.99'; select a.scheduledstart as StartTime, a.scheduledend as EndTime, a.ScheduledDurationMinutes as ScheduledDura

我不确定这里出了什么问题,但有人能帮我吗。我不熟悉在SQL中声明日期时间

declare @START datetime2 = '2013-07-17 00:00:00.00';
declare @END datetime2 = '2013-07-17 23:59:99.99';

select a.scheduledstart as StartTime, a.scheduledend as EndTime, a.ScheduledDurationMinutes as ScheduledDuration, a.activitytypecode, a.statecode, a.statuscode, a.OwnerId, b.new_SalesrepId as SalesRepID from ActivityPointerBase as a
join SystemUserExtensionBase as b on b.SystemUserId = a.OwnerId
where a.ActivityTypeCode = '4201' and a.StateCode = '1' and a.StatusCode = '3' and b.new_SalesrepId = 'CJV00100' and (a.ScheduledStart >= @START AND a.ScheduledEnd <= @END)
declare@START datetime2='2013-07-17 00:00:00.00';
声明@END datetime2='2013-07-1723:59:99.99';
从ActivityInterbase中选择a.scheduledstart作为开始时间,a.scheduledend作为结束时间,a.ScheduledDurationMinutes作为计划持续时间,a.activitytypecode,a.statecode,a.statuscode,a.OwnerId,b.new_SalesrepId作为SalesrepId作为
在b.SystemUserId=a.OwnerId上以b的身份加入SystemUserExtensionBase
其中a.ActivityTypeCode='4201'和a.StateCode='1'和a.StatusCode='3'和b.new_SalesrepId='CJV00100'和(a.ScheduledStart>=@START和a.ScheduledEnd您不能这样做:

declare @END datetime2 = '2013-07-17 23:59:99.99';
这样做:

declare @END datetime2 = '2013-07-17 23:59:59.99';
                                           ^^
记住它是年-月-日-小时:分钟:秒。分数和分钟从0到59,而不是99

此外,我更喜欢这样使用结束日期:

declare @END datetime2 = '2013-08-17'; --use "less than" the next day and forget time
WHERE yourColumn <@END
declare@END-datetime2='2013-08-17';--使用“少于”第二天并忘记时间

在yourColumn中,您试图为
@END
变量声明无效的时间。秒部分不能有99,因此将其更改为:

declare @START datetime2 = '20130717 00:00:00.00';
declare @END datetime2 = '20130717 23:59:59.99';

我还删除了日期中的
-
,以避免特定语言的格式。

我还尝试声明datetime而不是datetime2,没有用。。。