“FollowingTrialDate”类型是datetime
我想在单个字段中过滤日期。
如何在最近十五天内的FollowTrialDate字段中进行过滤。
如果有错误,它在哪里?
最诚挚的问候,
SELECT C.[No],
convert(date,CaseDate,103) as ModuleDate,
convert(date,FollowingTrialDate,103) as FollowingTrialDate,
ShortDescription,
Username,
Name,
Surname,
Email,
C.[Description] as [Desc],
'Davalar' as ModuleName
FROM [LegalIT_MnemonicTEST].[dbo].[Module_Case] C
inner join [System_User] su on C.LawyerID = su.UserID
where CONVERT(date,FollowingTrialDate,0)
between DATEADD(DD,-15,CONVERT(date,FollowingTrialDate,0)) and
DATEADD(DD,0,CONVERT(date,FollowingTrialDate,0))
答案 0 :(得分:0)
尝试以下代码(如果FollowTrialDate的类型是数据库中指定的日期时间)
请注意,如果您的CaseDate或FollowTrialDate已经在数据库中指定的类型'datetime',则无需先将其转换为日期以输出或过滤WHERE子句中使用的数据
SELECT C.[No],
convert(datetime,CaseDate) as ModuleDate,
FollowingTrialDate,
ShortDescription,
Username,
Name,
Surname,
Email,
C.[Description] as [Desc],
'Davalar' as ModuleName
FROM [LegalIT_MnemonicTEST].[dbo].[Module_Case] C
inner join [System_User] su on C.LawyerID = su.UserID
where FollowingTrialDate
between DATEADD(DAY, DATEDIFF(DAY, 0, dateadd(dd, -15, getdate())), 0) and
DATEADD(DAY, DATEDIFF(DAY, 0, getdate()), 0)