表pro
pro_id pro_name
 1       null
 2       null
我用 select * from pro where pro_name=''为什么取不到值?

解决方案 »

  1.   

    select * from pro where pro_name is null
      

  2.   

    注意 '' 和 null 是不等的!
    select * from pro where isnull(pro_name,'') = ''
      

  3.   


    ----测试一下就知道区别了
    declare @tb table (id int ,name varchar(10),name1 varchar(10))
    insert into @tb(id,name)
    select 1,''
    select * from @tb
    select id,LEN(name),LEN(name1) from @tb
    ------------
    id          name       name1
    ----------- ---------- ----------
    1                      NULL(1 行受影响)id                      
    ----------- ----------- -----------
    1           0           NULL(1 行受影响)
      

  4.   

    null 与‘’不同
    null 是什么也没有,表中pro_name 为null, 表示这个字段没有被赋过值
    ‘’是一个空字符串,表示这个字段赋过值,只不过,赋的是空字符串
      

  5.   

    http://blog.csdn.net/ynigeng/article/details/5716388
    看看吧,有些帮助,可以了解一下
      

  6.   

    select * from pro where isnull(pro_name,'') = ''
    蹭分..
      

  7.   

    在SQL中 默认的NULL是不等于''的
    可以通过 SET ANSI_NULL来设置
      

  8.   

    小三正解,是null的要用isnull来判断,null和''是有区别的,一个赋值而一个没赋值的区别
      

  9.   

    #10楼正解,可以设置一下 SET_ANSI_NULL ,select * from pro where pro_name = null
      

  10.   

    null 与‘’不同
    null 是什么也没有,表中pro_name 为null, 表示这个字段没有被赋过值
    ‘’是一个空字符串,表示这个字段赋过值,只不过,赋的是空字符串
      

  11.   

    set ansi_nulls off
    select * from pro where name=null
    if null=null 
    print 'a'
      

  12.   

    字段值为NULL的时候,WHERE子句需要使用IS NULL和IS NOT NULL来操作。在UPDATE语句时,可以使用UPDATE TABLE SET ABC=NULL。