select a.colid ,a.name ,b.name ,a.length from syscolumns a,systypes b where a.id= object_id('表名') and a.xtype=b.xtype order by a.colid 查询表字段,返回的是一个集合(多条属性)表中任意数据,只要其中一个字段为空,即返回,也就是返回“表中任意字段为空的数据” 只提供了表名,用一条sql语句编写,求高手解答,拜谢 

解决方案 »

  1.   


    ---->>TravyLee生成测试数据:
    if OBJECT_ID('test') is not null
    drop table test
    go
    create table test
    (
    id char(4),
    name varchar(51),
    temp varchar(51)
    )
    insert test
    select '0001','test01',null union all
    select '0002','test02','test02' union all
    select '0003','test03','test03' union all
    select null,null,'test04' union all
    select '0005','test05',null union all
    select '0006',null,null union all
    select '0007',null,null
    goselect
    *
    from
    test
    where
    (case when id is null then 1 else 0 end
    +case when name is null then 1 else 0 end
    +case when temp is null then 1 else 0 end)>0
    /*
    id   name                                                temp
    ---- --------------------------------------------------- ---------------------------------------------------
    0001 test01                                              NULL
    NULL NULL                                                test04
    0005 test05                                              NULL
    0006 NULL                                                NULL
    0007 NULL                                                NULL(5 行受影响)
    */