当前位置:Gxlcms > 数据库问题 > SQL获取前一天0:00:00至23:59:59数据

SQL获取前一天0:00:00至23:59:59数据

时间:2021-07-01 10:21:17 帮助过:2人阅读

@startDate DATE; DECLARE @startDateTime DATETIME; DECLARE @endDateTime DATETIME ; SET @startDate=GETDATE(); SELECT @startDateTime=DATEADD(DAY,-1,@startDate); SET @endDateTime=DATEADD(second,-1,CONVERT(DATETIME,@startDate)) print(@startDateTime) print(CONVERT(DATETIME,@startDate)) print(@startDate) print(@endDateTime)

 

技术分享

三、动态SQL语句

DECLARE @startDate DATE;
DECLARE @startDateTime DATETIME;
DECLARE @endDateTime DATETIME ;
SET @startDate=GETDATE();
SELECT @startDateTime=DATEADD(DAY,-1,@startDate); 
SET @endDateTime=DATEADD(second,-1,CONVERT(DATETIME,@startDate))

declare @sql nvarchar(1000)
set @sql=select * from E_OrdersLogistics  where ForecastTime>=‘‘‘+cast(ISNULL(@startDateTime,‘‘) as nvarchar(100))  +‘‘‘ and ForecastTime<‘‘‘+CAST(ISNULL(@endDateTime,‘‘) as nvarchar(100))+‘‘‘‘

print(@sql)

exec(@sql)

技术分享

如需转载,请注明出处,谢谢大家支持~

 

SQL获取前一天0:00:00至23:59:59数据

标签:

人气教程排行