假设表T里有字段A和字段B如何做查询语句在一个字段内输出:在字段A和B同时有值的时候返回字段B 没有的情况下返回字段A?用access 做。。所以不能用存储过程……

解决方案 »

  1.   

    select case when ((a is not null) and (b is not null)) then b else a end from tablename
      

  2.   

    select case when a is not null and b is not null then b else a end from tb
      

  3.   


    select case when (a is not null and b is not null) then b else a end from tb
      

  4.   

    iif函数iif(a is not null and b is not null ,b,a)select case when a is not null and b is not null then b else a end from tb
      

  5.   


    select case when A is null or B is null then A else B end from tb
      

  6.   

    LZ是用ACcess。
    所以必须用access的函数。
    iif,
    switch
    select iif(a is not null and b is not null ,b,a)select switch(a is not null and b is not null,b,a is  null or b is not null,a)1.IIf   函数   
        
      根据表达式的值,来返回两部分中的其中一个。  
       
      语法   IIf(expr,   truepart,   falsepart)  
       
      IIf   函数的语法含有下面这些命名参数:  
       
      部分   描述    
      expr   必要参数。用来判断真伪的表达式。    
      truepart   必要参数。如果   expr   为   True,则返回这部分的值或表达式。    
      falsepart   必要参数。如果   expr   为   False,则返回这部分的值或表达式。 
         
      说明  
       
      由于   IIf   会计算   truepart   和   falsepart,虽然它只返回其中的一个。因此要注意到这个副作用。例如,如果   falsepart   产生一个被零除错误,那么程序就会发生错误,即使   expr   为   True。  
     
    select   iif(col='0','ok',iif(col='1','err1',iif(col='2','err2','err3')))   as   colname  
      from   table
     
    2. Switch
    在Access无法使用SQL语句中的case when语句,但可以通过Switch函数实现
    例如:
    Switch(成绩<60,"不及格",成绩 Between 61 And 74,"中",成绩 Between 75 And 88,"良",成绩 Between 88 And 100,"优") AS 成绩等级
    可以实现对成绩的值进行多分支条件判断结构
      

  7.   

    select case when (a is not null and b is not null) then b else a end from tb