sql 语句:select date= 
case
when (select L_loan_info.defer_type from L_loan_info) ='0' then L_loan_info.cust_apply_duedate
when (select L_loan_info.defer_type from L_loan_info)<>'0' then L_extd_apply.cont_extd_date 
end 消息:消息 4104,级别 16,状态 1,第 1 行
无法绑定由多个部分组成的标识符 "L_loan_info.cust_apply_duedate"。
消息 4104,级别 16,状态 1,第 1 行
无法绑定由多个部分组成的标识符 "L_extd_apply.cont_extd_date"。
我想查询一个日期字段,如果L_loan_info表的defer_type字段为0就用这张表的“cust_apply_duedate”作为查询字段,
如果不为0则用另一张表L_extd_apply的 “cont_extd_date”作为查询字段 。   

解决方案 »

  1.   

    select top 1 date= 
    case 
    when L_loan_info.defer_type ='0' then L_loan_info.cust_apply_duedate 
    else L_extd_apply.cont_extd_date 
    end 
    from L_loan_info,L_extd_apply
      

  2.   

    没有from啊。L_loan_info.cust_apply_duedate->
    L_loan_info.dbo.cust_apply_duedate??
      

  3.   

    我是要查银行贷款的逾期查询 本来就要比较L_loan_info表的cust_apply_duedate 字段 现在贷款又可以展期了 所以我要判断这笔贷款是否展期 如果展期则用展期表的 还款日期 比较 ,如果没展期则就用L_loan_info的cust_apply_duedate比较
      

  4.   

    select L_loan_info.defer_type from L_loan_info
    处要保证只返回一条记录。
    改成 表名.字段名=
    或者先赋值,然后再case
      

  5.   


    select count(*) from L_loan_info    十五条记录
    select count(*) from L_extd_apply    六条记录select date= 
    case 
    when L_loan_info.defer_type ='0' then L_loan_info.cust_apply_duedate 
    else L_extd_apply.cont_extd_date 
    end 
    from L_loan_info,L_extd_apply      就是条记录 我想得到的或十五条记录 或六条记录 为什么会出现90条记录。