select NE, StartTime,Type,sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat --本身语法就有问题 --你的语句有没有贴完整
我怕太长了(select NE, Type,convert(varchar (20),StartTime,120) AS StartTime isdate(),sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat where StartTime >= dateadd(hour,-24,getdate()) group by NE,StartTime,Type) union (select NE,StartTime,'所有' as Type,sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat where StartTime >= dateadd(hour,-24,getdate()) group by NE,StartTime) order by NE,StartTime desc,Type
用这个试下 cast(startdate of smalldatetime)
我怕太长了(select NE, Type,convert(varchar (20),StartTime,120) AS StartTime isdate(),sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat where StartTime >= dateadd(hour,-24,getdate()) group by NE,StartTime,Type) union (select NE,StartTime,'所有' as Type,sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat where StartTime >= dateadd(hour,-24,getdate()) group by NE,StartTime) order by NE,StartTime desc,Type --------- 红色部分什么意思?
--try select NE, convert(varchar (20),StartTime,120) AS StartTime,Type,sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat.....where isdate(StartTime)=1
这样: --我怕太长了 (select NE, Type,convert(varchar (20),StartTime,120) AS StartTime isdate(),sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat where StartTime >= dateadd(hour,-24,getdate()) group by NE,StartTime,Type) union (select NE,StartTime,'所有' as Type,sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat where StartTime >= dateadd(hour,-24,getdate()) group by NE,StartTime) order by NE,Star…
这样用法怎么可能对? AS StartTime isdate() -->as StartTime --isdate()去掉,在条件中where isdate(StartTime)=1 看看
try:(select NE, [Type],convert(varchar (20),StartTime,120) AS StartTime,sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat where StartTime >= dateadd(hour,-24,getdate()) group by NE,StartTime,Type) union (select NE,'所有' as [Type],StartTime,sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat where StartTime >= dateadd(hour,-24,getdate()) group by NE,StartTime) order by NE,StartTime desc,Type union 连接的两个结果集的列必须一一对应,类型也必须一致。 你把字符型和smalldatetime型对应,当然会报错。
--本身语法就有问题
--你的语句有没有贴完整
cast(startdate of smalldatetime)
红色部分什么意思?
select NE, convert(varchar (20),StartTime,120) AS StartTime,Type,sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat.....where isdate(StartTime)=1
--我怕太长了
(select NE, Type,convert(varchar (20),StartTime,120) AS StartTime isdate(),sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat where StartTime >= dateadd(hour,-24,getdate()) group by NE,StartTime,Type) union (select NE,StartTime,'所有' as Type,sum(UsrReg) as UsrReg from UndcHistory.dbo.HLRHourStat where StartTime >= dateadd(hour,-24,getdate()) group by NE,StartTime) order by NE,Star…
AS StartTime isdate()
-->as StartTime --isdate()去掉,在条件中where isdate(StartTime)=1
看看
from UndcHistory.dbo.HLRHourStat
where StartTime >= dateadd(hour,-24,getdate())
group by NE,StartTime,Type)
union
(select NE,'所有' as [Type],StartTime,sum(UsrReg) as UsrReg
from UndcHistory.dbo.HLRHourStat
where StartTime >= dateadd(hour,-24,getdate())
group by NE,StartTime)
order by NE,StartTime desc,Type
union 连接的两个结果集的列必须一一对应,类型也必须一致。
你把字符型和smalldatetime型对应,当然会报错。