现在想写一个sql,是从客户端传到服务端的,客户端有几个选填项,比如 A,B,C,D客户可能选其中的几项填写进行查询。我不想if哪个空来拼写where语句。想这样直接将abcd都写到where中where a=,b=,c=,d=;当然,等号后面都要有值,这就是我的问题。等号后面填写什么字符串默认取所有值?a=a是可以的,但是a不是字符串啊谢谢大家乐

解决方案 »

  1.   

    where col1=case when A is null then col1 
    and col2=case when b is null then col2
    and col3=case when c is null then col4 
    and col4=case when d is null then col5 
      

  2.   

    谢谢楼上两位,我的意思不是这样的,select * from table1 where a=a,b=b,c=c,d=100;这样取出来的集合也就是d=100时候的集合,但是 a=a后面的值不是字符串。我想问问有没有等号后面的通配符,想like 后面的‘%’这样的东西
      

  3.   

    like也是针对字串的,而你又不是字串,不明白你需求
      

  4.   

    2楼可以啊
    a后面不是字符串  是一个判断
    相当于
    if a is null
    a=a
    else
    a=你的值
    end if;
      

  5.   

    没听明白楼主什么意思,弱弱的问一句,select * from table1 where a=a,b=b,c=c这是什么写法,