输入banner图图片脚本导航/分类

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

@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数据

标签: