时间:2021-07-01 10:21:17 帮助过:2人阅读
三、动态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数据
标签: