我有一个表tb,字段是state(int型)和jongjifen(int型)我想根据jongjifen这个字段自动生成state的值,如果jongjifen大于200的话,state=1 ,如果小于等于200的话等于0,在公式里是如何写的?

解决方案 »

  1.   

    state=case when ongjifen>200 then 1 else 0 end
      

  2.   

    select (case when jongjifen>200 then 0 else 1 end) as state from tb
      

  3.   

    if object_id('[tb]') is not null drop table [tb]
    go
    create table [tb](
    [state] as case when jongjifen>200 then 1 else 0 end,
    [jongjifen] int
    )
    go
    insert tb(jongjifen) 
    select 200 union all
    select 201 union all
    select 2
    goselect * from tb
    /**
    state       jongjifen   
    ----------- ----------- 
    0           200
    1           201
    0           2(所影响的行数为 3 行)
    **/
      

  4.   

    --SQL Server一个字段的默认值公式不能引用另外一个字段的值!
      

  5.   

    我说是在字段下面列属性的"公式"里面写代码。。state字段是存在的。根据jongjifen这个字段生成。。如何在公式里写,用case语句
      

  6.   

    update table set state=case when jongjifen>200 then 1 else 0 end
      

  7.   

    select case when jongjifen>200 then 1 else 0 end 
    from table1
      

  8.   

    case when  ..
       then ..
          else..
    end
      

  9.   

    自己翻开资料找答案的。正确的是这样的state字段的公式:case when jongjifen>200 then 1 else 0 end有些人别看不懂问题意思就说什么看不懂中国话什么的。。虽然我很菜.谢谢