把三项加起来
--通话流水账单
select [CallerNumber]
,[TelNum]
,datediff(second,[StartDateTime],[EndDateTime]) as '通话时间'
from [mydb2].[dbo].[T_CallRecords1]
union all
--总长话
select '长话时长',sum(datediff(second,StartDateTime,EndDateTime)),''
from T_CallRecords1
where TelNum Like '0%'
union all
--总市话
select '市话时长',sum(datediff(second,StartDateTime,EndDateTime)),''
from T_CallRecords1
where TelNum not Like '0%'
select [CallerNumber] ,[TelNum] ,datediff(second,[StartDateTime],[EndDateTime]) as '通话时间'
from [mydb2].[dbo].[T_CallRecords1]
的列对不上,当你补充后,你试着将你语句中获取的时长转换成字符串形式,如Convert(nvarcahar(50),sum(datediff(second,StartDateTime,EndDateTime))),CallerNumber也转换成字符串形式,Convert(nvarchar(50),CallerNumber),总之,要用到Union all时,每个列的数据类型及长度要一样! 作者: 徐瑞 时间: 2012-4-16 09:49
select [CallerNumber]
,[TelNum]
,datediff(second,[StartDateTime],[EndDateTime]) as '通话时间'
from [mydb2].[dbo].[T_CallRecords1]
union all
--总长话
select '长话时长',sum(datediff(second,StartDateTime,EndDateTime)),''
from T_CallRecords1
where TelNum Like '0%'
union all
--总市话
select '市话时长',sum(datediff(second,StartDateTime,EndDateTime)),''
from T_CallRecords1
where TelNum not Like '0%'