想实现case when的then后面实现赋值操作,类似于case when ..then num1='2',num2='3',num1,num2是两个自定义字段,表中其实没有的,为了在页面显示用的

解决方案 »

  1.   

    后台sql拼接 或者存储传参数 
      

  2.   

    我就是想知道这个sql怎么写啊
      

  3.   

    你的意思是下面这样的???
    select c1,
           c2,
           case
             when c1 = 11 then
              2
           end num1,
           case
             when c2 = 11 then
              3
           end num2
      from c;
      

  4.   

    能不能:case when ..then '2' end as num1
    case when ..then '3' end as num2
      

  5.   

    不是3楼你那是case when最基本的用法,我的意思是then后面给5个数据库字段赋值
      

  6.   


    “给数据库字段赋值”,就一种方法: insert如果你的case when then 在值的位置,可以,
    如果在字段的位置,不能。必须借助其它编程语言(Java,c#,c++...)或者PL/SQL。
      

  7.   


    一个case when 只能给一个字段赋值。。要给多个字段赋值,必须得有多个case when才行。写多个case when 为什么不行??????
      

  8.   

    一整个case when then end 只返回一个字段
    如果你要五个字段,就写5个case when..end