本帖最后由 yangyhq 于 2012-04-12 12:58:42 编辑

解决方案 »

  1.   

    这个可以用动态SQL,比如:
    declare @basicsql varchar(8000),
            @whereclause varchar(4000)set @basicsql ='基本的查询语句'if (条件判断)
    begin
        set @whereclause =' where (Code=X1 & Value=1) AND (Code=X2 & Value=3)'
    end
    else
    begin
        set @whereclause =' where (Code=X1 & Value=1) OR (Code=X2 & Value=3)'
    endset @basicsql=@basicsql+@whereclause exec (@basicsql)
    如果还有很多条件,可以一个一个加到@whereclause后面,最后拼接成一个完整的sql动态语句,执行下就可以了。
      

  2.   

    你的意思是不是这个意思?按我的理解,没有结果的语句应该这样写
    因为你写得&是位运算符,不是别的什么语言里的 与 的意思。
    select *
    from table
    where code=x1 and value=1 and code=x2 and value =3
    这个要满足两个条件肯定是没有结果的啊
     

    select *
    from table
    where code=x1 and value=1 or code=x2 and value =3
    这个肯定是有两个输出结果的啊。