表1
A B
1 中国
2 美国
3
4 英国
5
6 法国
7结果表2
A B
1 中国
2 美国
3 美国
4 英国
5 英国
6 法国
7 法国就是将表1中B列中所有是空值的记录变成是它上一行的值。
A B
1 中国
2 美国
3
4 英国
5
6 法国
7结果表2
A B
1 中国
2 美国
3 美国
4 英国
5 英国
6 法国
7 法国就是将表1中B列中所有是空值的记录变成是它上一行的值。
解决方案 »
- 求条删除语句
- 有一个SP,我想在每天自动运行我的一个这个Sp一次
- 如何在查询分析器里面执行一语句后,可将全部存储过程加密,一个个加密太慢,好多过程,在线等立刻给分
- 怎样把一个表中的多个字段合并为一个字段,并把新数据插入到新表中
- 将数据类型 varchar 转换为 numeric 时出错。请教!~
- 创建存储过程,列名以参数传入,聚合函数sum(列名)无效
- 什么时候该用存储过程?邹老大能给我发一些资料么
- 竹老大为何闭关?
- DTS导出数据到Excel的时候能不能动态指定Excel的路径和文件名?急!100分相送!
- 有谁知道关于PERSONAL版ORACLE8方面的书?
- 复杂的表关联,怎么设计好??
- SQL2000 企业管理器生成表脚本的问题
set b = tp.b
from table1 a,table1 tp
where a.a = tp.a -1 and a.b is null
update 表1 t
set
B=(select top 1 B from 表1 where A<t.A and B is not null order by A desc)
where
t.B is null
insert @t1 select
1 ,'中国' union select
2 ,'美国' union select
3 ,null union select
4 ,'英国' union select
5 ,null union select
6 ,'法国' union select
7 ,null
update a
set b = tp.b
from @t1 a,@t1 tp
where a.a = tp.a +1 and a.b is nullselect * from @t1
/*
A B
----------- ----------
1 中国
2 美国
3 美国
4 英国
5 英国
6 法国
7 法国(所影响的行数为 7 行)*/
if object_id('tempdb.dbo.#1') is not null drop table #1
create table #1 (A int,B varchar(4))
insert into #1
select 1,'中国' union all
select 2,'美国' union all
select 3,null union all
select 4,'英国' union all
select 5,null union all
select 6,'法国' union all
select 7,nullselect A, B=
case
when B is not null then B
else (select top 1 B from #1 where A <= a.A and B is not null order by A desc)
end
from #1 a/*
A B
1 中国
2 美国
3 美国
4 英国
5 英国
6 法国
7 法国
*/
A,B=isnull((select top 1 B from T where A<a.A order by ID desc),B)--为null时
from
T aselect
A,B=isnull(nullif((select top 1 B from T where A<a.A order by ID desc),''),B)--为''时
from
T a
insert @t1 select
1 ,'中国' union select
2 ,'美国' union select
3 ,null union select
4 ,'英国' union select
5 ,null union select
6 ,'法国' union select
7 ,null
---1
update a
set b = isnull(a.b,tp.b )
from @t1 a,@t1 tp
where a.a = tp.a +1
--2
update a
set b = tp.b
from @t1 a,@t1 tp
where a.a = tp.a +1 and a.b is null--3
update a
set b = COALESCE(a.b,tp.b )
from @t1 a,@t1 tp
where a.a = tp.a +1
select * from @t1
/*
A B
----------- ----------
1 中国
2 美国
3 美国
4 英国
5 英国
6 法国
7 法国(所影响的行数为 7 行)*/
create table #(id int,cName nvarchar(10))
insert # select
1 ,'中国' union select
2 ,'美国' union select
3 ,null union select
4 ,'英国' union select
5 ,null union select
6 ,'法国' union select
7 ,null
select * from #update # set cName=
(
select top 1 Last.cName from # Last
where Last.id<#.id
and (Last.cName is not null or len(Last.cName)<>0)
order by Last.id desc
)
where cName is null or len(cName)=0 select * from #
drop table #