select col1 from tbl1 where 1=2
故意给个假条件,想查出一空行来,怎样才能使col1为null值

解决方案 »

  1.   

    where 1=2
    这个条件恒不成立,所以取不到行,自然得不到结果集中某列为null的结果.直接 SELECT NULL 即可.
      

  2.   

    select col = case when getdate() > getdate() - 1 then 'null' end/*
    col
    ----
    null(1 行受影响)
    */
      

  3.   

    select null col/*
    col
    -----------
    NULL(1 行受影响)
    */
      

  4.   

    select top 1 null  from @tb
      

  5.   

    select  top 1 null as  col1   from   tbl1   where   1=1 带from 的时候,结果集中没有符合调节的记录是不会出数据的
      

  6.   

    select * from table where id is null
      

  7.   

    select   col1   from   tbl1   where   col1   is null
      

  8.   

    select col1=isnull(null,'')--测试isnull
    --------
    select   col1   from   tbl1   where col1 is null--加上条件
      

  9.   

    select null as col from tabl1
    select (case when ‘条件’ then ‘值’ else null end) as col from tabl1
      

  10.   

    declare @tb table (id int)
    insert into @tb select 1
    insert into @tb select 2
    insert into @tb select 3select top 1 id=null from @tb 
    /*
    id
    NULL
    */
      

  11.   

    select isnull(name,'null')
    from table