"B10和B20填入之下的NULL資料值  且自動保持"
没看懂

解决方案 »

  1.   

    此資料來自于EXCEL中, 故而出現以上的問題,  回robin_yao(嘘) 
        就是能成為如下的資料
        F1        F2
        B10     E槽位
        B10     F槽寬
        B10     NULL
        ...       ....
        select f1,count(*) from table group by f1
        值:B10   10
        
      

  2.   

    declare @col varchar(20)
    set @col=''
    update tb set f1=@col,
    @col=case when f1 is null then @col else f1 end
      

  3.   

    create table t(F1 varchar(20),F2 varchar(20))insert t
    select 'B10','E槽位' union all
    select NULL,'F槽寬' union all
    select NULL,'G槽徑' union all
    select NULL,NULL union all
    select NULL,NULL union all
    select 'B20','去端面釘' union all
    select NULL,'F槽寬' union all
    select NULL,'G槽徑' union all
    select NULL,NULL union all
    select NULL,NULL
    go
    alter table t add id int identity(1,1)
    goupdate t
    set F1=(case when a.F1 is null then (select top 1 F1 from t 
    where id<a.id and F1 is not null
    order by id desc) else a.F1 end)
    from t a
    go
    alter table t drop column id
    go
    select * from t
    drop table tF1                   F2                   
    -------------------- -------------------- 
    B10                  E槽位
    B10                  F槽寬
    B10                  G槽徑
    B10                  NULL
    B10                  NULL
    B20                  去端面釘
    B20                  F槽寬
    B20                  G槽徑
    B20                  NULL
    B20                  NULL(所影响的行数为 10 行)
      

  4.   

    楼主的表格设计存在很大问题,没有标识键,这样可以出现大量重复的null,null不便于删除和查询!
      

  5.   

    这个最好是在Excel中将原始数据修改成你要的这种格式.
    因为"要在B10和B20之间保持10行,且对有F1有NULl的也要用B10来填充"用SQL语句来实现是比较困难的...
      

  6.   

    set nocount on
    create table tb (f1 varchar(20),f2 varchar(20))
    go
    insert into tb
    select 'B10','E槽位' union all
    select null,'F槽寬' union all
    select null,'G槽徑' union all
    select null,null union all
    select null,null union all
    select 'B20','去端面釘' union all
    select null,'F槽寬' union all
    select null,'G槽徑' union all
    select null,null union all
    select null,nulldeclare @col varchar(20)
    set @col=''
    update tb set f1=@col,
    @col=case when f1 is null then @col else f1 end --test
    select * from tb
    --drop 
    drop table tb
      

  7.   

    謝謝  wgsasd311(自强不息) --已經解決一半問韙
       且還有    F1        F2
        B10     E槽位
        B10     F槽寬
        B10     NULL
        ...       ....
        select f1,count(*) from table group by f1
        值:B10   10
                 --------以上count(*)=10的問韙.   本身大于10的刪除..
            多謝各位了...
      

  8.   

    呵呵.  
      回robin_yao(嘘)
     
      相信我們大家都在學習.只要有收獲就有進步.../  三月份我將80%時間投入SQL.界時各位多多幫忙.合作.