TRY: 1,建立序数表 select top 8000 identity(int,1,1) as N into numtab from (select top 100 id=1 from sysobjects) as a, (select top 100 id=1 from sysobjects) as b, (select top 100 id=1 from sysobjects) as c示,select a.a,a.b+N,a.c,a.d from (select * from table where c is not null)a left join Num b on a.c-a.b>=b.N Union all select * from table where c is null
TRY:忘了你的BC字段可能不是日期型了。:) select a.a,cast(a.b as datetime)+N,a.c,a.d from (select * from table where c is not null)a left join Num b on cast(a.c as datetime)-cast(a.b as datetime)>=b.N Union all select * from table where c is null
调试正确的代码:select top 8000 identity(int,0,1) as N into num from (select top 100 id=1 from sysobjects) as a, (select top 100 id=1 from sysobjects) as b, (select top 100 id=1 from sysobjects) as c select a.a,convert(char(10),cast(a.b as datetime)+N ,120) b,a.c,a.d from (select * from table where c is not null)a left join Num b on cast(a.c as datetime)-cast(a.b as datetime)>=b.N Union all select * from table where c is null
1,建立序数表
select top 8000 identity(int,1,1) as N into numtab from
(select top 100 id=1 from sysobjects) as a,
(select top 100 id=1 from sysobjects) as b,
(select top 100 id=1 from sysobjects) as c示,select a.a,a.b+N,a.c,a.d from
(select * from table where c is not null)a
left join Num b on a.c-a.b>=b.N
Union all
select * from table where c is null
select a.a,cast(a.b as datetime)+N,a.c,a.d from
(select * from table where c is not null)a
left join Num b on cast(a.c as datetime)-cast(a.b as datetime)>=b.N
Union all
select * from table where c is null
(select top 100 id=1 from sysobjects) as a,
(select top 100 id=1 from sysobjects) as b,
(select top 100 id=1 from sysobjects) as c
select a.a,convert(char(10),cast(a.b as datetime)+N ,120) b,a.c,a.d from
(select * from table where c is not null)a
left join Num b on cast(a.c as datetime)-cast(a.b as datetime)>=b.N
Union all
select * from table where c is null
我不想把代码拷贝来就用!谢谢!