数据表table的形式如下
ID  A    B     C     D    E
1   10   null  10    null null
2   null 20    20    20    null
3   null 20    null  30    40
.
.
.
当我用select *from table where ID =1
这样的话就把所有的列都列出来
我现在上怎么用一个语句 当我查询到某一行的时候把是NULL的列不显示呢?
例如                                   ID A C
select *from table where ID =1 结果要是1 10 10
                                         B  C  D
select *from table where ID =2 结果要是2 20 20 20

解决方案 »

  1.   

    我现在上怎么用一个语句 当我查询到某一行的时候把是NULL的列不显示呢?   用一个查询语句无法实现!!因为你最后显示的列不确定,我写到这写不下去了,你参考一下。select *
      from (select id,
                   decode(rownum, 1, A, 2, B, 3, C, 4, D, 5, E) ex,
                   decode(rownum, 1, 'A', 2, 'B', 3, 'C', 4, 'D', 5, 'E') col
              from (select 1 id, 10 A, null B, 10 C, null D, null E from dual)
            connect by rownum <= 5)
     where ex is not null;
      

  2.   

    select 1 id, 10 A, null B, 10 C, null D, null E from dual
    可以换成
    select *from table where ID =1 
      

  3.   

    好像不对 我的查询条件是只读取数据库上的某一行
    例如当我读取ID=1这一行的时候 在这行的显示的内中中ABCDE这5列上如果那一列的内容是NULL的话就不显示
    所以ID=1的结果要10,10
    如果是ID=2的结果要 20,20,20
      

  4.   

    还有一个问题 我的数据库是SQL 2000的个人版 还想它不识别decode函数
      

  5.   

    还是,是否是以下格式ID  A    B    C    D    E 
    1  10         10   
    2       20    20    20 
    3       20          30    40 
      

  6.   

    ABCDE列是数值INT 不过可以为空
      

  7.   


    /*
    CREATE TABLE [TNULL] (
    [A] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
    [B] [int] NULL ,
    [C] [int] NULL ,
    [D] [int] NULL 
    ) ON [PRIMARY]
    --GOinsert into tnull 
    select '1',null,10,10 union all
    select '2',20,null,20 union all
    select '3',null,null,30
    */
    select * from tnull
    /*
    1 NULL 10 10
    2 20 NULL 20
    3 NULL NULL 30
    */
    select A,
    (case isnull(B,0) when 0 then '' else CAST(B AS varchar(12)) end) as B,
    (case isnull(C,0) when 0 then '' else CAST(C AS varchar(12)) end) as C,
    (case isnull(D,0) when 0 then '' else CAST(D AS varchar(12)) end) as D
     from tnull
    /*
    1 10 10
    2 20 20
    3 30
    */