Sql server 如何在不更改日期的情况下提取当前日期和时间

Sql server 如何在不更改日期的情况下提取当前日期和时间,sql-server,Sql Server,有人能告诉我如何改变这一点,使它总是拉当前的一天吗 SELECT Groups.GroupName, AgentTeams.TeamName, [Agent.Firstname] & [ Agent.Lastname, CRC.Description, Count(History.HistoryID) AS [CRC Count] FROM ((GroupAgent INNER JOIN Groups ON GroupAgent.GroupID = Groups.GroupID) INN

有人能告诉我如何改变这一点,使它总是拉当前的一天吗

SELECT Groups.GroupName, AgentTeams.TeamName, [Agent.Firstname] & [ Agent.Lastname, CRC.Description, Count(History.HistoryID) AS [CRC Count]
FROM ((GroupAgent INNER JOIN Groups ON GroupAgent.GroupID = Groups.GroupID) INNER JOIN ((Agent LEFT JOIN History ON Agent.AgentID = History.AgentID) LEFT JOIN CRC ON History.CRC = CRC.CRC) ON  GroupAgent.AgentID = Agent.AgentID) INNER JOIN (AgentTeams INNER JOIN AgentStartDates ON  AgentTeams.TeamID = AgentStartDates.TeamID) ON GroupAgent.AgentID = AgentStartDates.AgentID
WHERE (((History.CallDateTime) Between CONVERT(Datetime,'20/11/2014 00:00:01',105) And CONVERT(Datetime,'20/11/2014 23:59:01',105))) 
GROUP BY Groups.GroupName, AgentTeams.TeamName, Agent.Firstname, Agent.Lastname, CRC.Description
ORDER BY Groups.GroupName, AgentTeams.TeamName;
假设您的意思是History.CallDateTime是当前日期:

WHERE History.CallDateTime >= CAST(CAST(GETDATE() AS DATE) AS DATETIME)
    AND History.CallDateTime < CAST(CAST(DATEADD(dd,1,GETDATE()) AS DATE) AS DATETIME) 
如果您使用的是SQL Server 2005或更早版本,则需要使用:

WHERE History.CallDateTime >= DATEADD(dd, DATEDIFF(dd, 0, getdate()), 0)
    AND History.CallDateTime < DATEADD(dd, DATEDIFF(dd, 0, getdate()) + 1, 0)

这非常有效,谢谢: