想求上月一号凌晨到最后一天24点的数据
不知道这样写对不对啊
高手指点迷津declare @tempmonth datetime
set @tempmonth = left(dateadd(mm,-1,getdate()),7)select * from Month where between @tempmonth + '00:00:00' and @tempmonth + '23:59:00'
不知道这样写对不对啊
高手指点迷津declare @tempmonth datetime
set @tempmonth = left(dateadd(mm,-1,getdate()),7)select * from Month where between @tempmonth + '00:00:00' and @tempmonth + '23:59:00'
这个是小弟新写的
高手帮忙看看阿declare @tempmonth datetime
set @tempmonth = left(dateadd(mm,-1,getdate()),7)select * from Month where Time between @tempmonth + '00:00:00' and @tempmonth + '23:59:00'
select * from month where year(time)*12+month = year(getdate())*12+month(getdate())-1
declare @endDate datetime --下月第一天
declare @nowDate datetime --本月第一天
set @starDate=dateadd(month,-1,Convert(varchar(8),getdate(),120)+@statusDay)
set @endDate=dateadd(month,1,Convert(varchar(8),getdate(),120)+@statusDay)
set @nowDate=dateadd(month,0,Convert(varchar(8),getdate(),120)+@statusDay)有了这些值你就可以去判断了
这个不是很清楚阿
declare @last datetime,@this datetime
set @last = left( convert(varchar(10),dateadd(mm,-1,getdate()),111),7)
set @this = left(convert(varchar(10),getdate(),111),7)
select * from dbo.Tbl_Agent_Hour where StatisticsTime between @last+'00:00:00' and @this+'00:00:00' 总是说“从字符串转换为 datetime 时发生语法错误。”
declare @endDate datetime --下月第一天
declare @nowDate datetime --本月第一天
set @starDate=dateadd(month,-1,Convert(varchar(8),getdate(),120)+@statusDay)
set @endDate=dateadd(month,1,Convert(varchar(8),getdate(),120)+@statusDay)
set @nowDate=dateadd(month,0,Convert(varchar(8),getdate(),120)+@statusDay)
print @starDate
print @endDate
print @nowDate
时说“必须声明变量 '@statusDay'。”
declare @last varchar(),@this varchar()
set @templastmonth = left( convert(varchar(10),dateadd(mm,-1,getdate()),120),7)
set @tempthismonth = left(convert(varchar(10),getdate(),120),7)selcet * from 数据表 where 查询时间 between cast(@templastmonth+'-01 00:00:00' as datetime) and cast(@tempthismonth+'-01 00:00:00' as datetime)
where year(查詢時間)=year(dateadd(mm,-1,getdate()))
and month(查詢時間)=month(dateadd(mm,-1,getdate()))--或者
select * from 數據表
where 查詢時間>=convert(datetime,convert(char(07),dateadd(mm,-1,getdate()),120)+'-01')
and 查詢時間<convert(datetime,convert(char(07),getdate(),120)+'-01')
这句也可以啊
set @first=convert(char(8),dateadd(month,-1,getdate()),120)+'1'
set @end=convert(char(8),getdate(),120)+'1'
select @first--上个月第一天
select @end--上个月的最后一天