Sql server 2008 SQL选择前一天并排除今天

Sql server 2008 SQL选择前一天并排除今天,sql-server-2008,tsql,Sql Server 2008,Tsql,我需要包括昨天注册的所有记录,但不包括今天注册的任何记录。我不确定这个查询是否给出了正确的记录数。请帮忙 select id, lastmodifieddate from stu_tbl where last_modified_date > DATEADD(d, - 1, GETDATE())) and _last_modified_date <> GETDATE()) 从stu\u tbl中选择id、lastmodifieddate 其中上次修改日期>日期添加(d,-

我需要包括昨天注册的所有记录,但不包括今天注册的任何记录。我不确定这个查询是否给出了正确的记录数。请帮忙

select id, lastmodifieddate  from stu_tbl
where last_modified_date > DATEADD(d, - 1, GETDATE())) 
and _last_modified_date <>  GETDATE())
从stu\u tbl中选择id、lastmodifieddate
其中上次修改日期>日期添加(d,-1,GETDATE())
和_last_modified_date GETDATE())
试试这个:

select id, last_modifieddate  from stu_tbl
where last_modified_date >= DATEADD(d, -1, cast(GETDATE() as date)) 
  and last_modified_date < cast(GETDATE() as date) 
从stu\u tbl中选择id,最后修改日期
其中上次修改日期>=DATEADD(d,-1,cast(GETDATE()作为日期))
最后一次修改日期
以下是SQL Server 2008+解决方案:

select id, lastmodifieddate  
from stu_tbl
where last_modified_date >= cast(dateadd(day, -1, GetDate()) as Date)
and last_modified_date < cast(GetDate() as Date)
选择id,最后修改日期
来自stu_tbl
其中上次修改日期>=cast(dateadd(day,-1,GetDate())作为日期)
最后一次修改日期
试试这个

declare @Dfrom  datetime
declare @Dto    datetime
declare @Dyesterday datetime

--Get date before current date
set @Dyesterday = dateadd(day, -1, getdate())

--Set date from to 12am
set @Dfrom = CONVERT(varchar(20), @Dyesterday, 101)

--set date to to 11:59:59PM
set @Dto = CONVERT(varchar(20), @Dyesterday, 101) + ' 23:59:59'

--if date and time is required
select  id, lastmodifieddate
from    stu_tbl
where   last_modified_date between @Dfrom and @Dto


谢谢,但是最后一行和最后一天
--if date only and time is not required
select  id, lastmodifieddate
from    stu_tbl
where   last_modified_date = @Dfrom