表两列A,B如下:A         B
0 NULL
1 15:00     
0 NULL
0 16:00如果当列A为1的时候就不显示B列的数据,当A为0的时候就显示。用SELECT查询可以吗?应该怎么写啊?

解决方案 »

  1.   

    select a,b=case when a=0 then b else null end
    from tb
      

  2.   

    select B from table where A=(select  A from table where A=0)
      

  3.   


    select a,case when a=1 then null else b end b
    from tb
      

  4.   

    select a,b=case when a=0 then b else null end
    from tba          b
    ----------- -----------------------
    0           NULL
    1           NULL
    0           NULL
    0           16:00(4 行受影响)
      

  5.   


    drop table #temp
    go
    create table #temp
    (
    A int,
    B varchar(100)
    )
    goinsert into #temp values(0, NULL)
    insert into #temp values(1, '15:00')
    insert into #temp values(0, NULL)
    insert into #temp values(0, '16:00')select * from #temp
    goselect a, (case when a = 1 then NULL else B end) as B
    from #temp
      

  6.   


    首先谢谢诸位的帮助,以上命令我在SQL2000中运行,出现'='附件有错误,但把b=去掉后就运行成功了。
    select a,case when a=0 then b else null end
    from tb