declare @dt datetime set @dt=cast('' as datetime) select @dt=@dt+begintime from 表這樣?
if object_id('tb','u') is not null drop table tb go create table tb ( begintime datetime ) go insert into tb select '2011-11-11' union all select '2011-11-12' union all select '2011-11-13' go select stuff((select ','+cast(begintime as varchar) from tb for xml path('')),1,1,'') /* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 11 11 2011 12:00AM,11 12 2011 12:00AM,11 13 2011 12:00AM(1 行受影响)*/
计算出来后
同样可以用sum()求和
set @dt=cast('' as datetime)
select @dt=@dt+begintime from 表這樣?
if object_id('tb','u') is not null
drop table tb
go
create table tb
(
begintime datetime
)
go
insert into tb
select '2011-11-11' union all
select '2011-11-12' union all
select '2011-11-13'
go
select stuff((select ','+cast(begintime as varchar) from tb for xml path('')),1,1,'')
/*
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
11 11 2011 12:00AM,11 12 2011 12:00AM,11 13 2011 12:00AM(1 行受影响)*/
INSERT @t SELECT '01:00'
INSERT @t SELECT '03:00'
DECLARE @dt DATETIME
SET @dt=''
SELECT @dt=@dt+begintime FROM @tSELECT @dt--同默認日期換算
/*
1900-01-01 04:00:00.000*/