我有一个数据库
  BOOK
有一个字段  ISCHECKED  int  (0,1)我想点一个按钮后,自动判断SQL的值
如果为1就就把值改为0
如果为0就把值改为1不想用到.NET里面的
if(...==0){...}
想直接在SQL中判断~
 
请大虾们赐教

解决方案 »

  1.   

    我简单的理解了下你的意思不知道理解的准确不准确,如果是我,我或许会选择用存储过程
    Create Proc upStr
    @num int
    AS 
    if(@num=0)
    begin
    update Tab set ISCHECKED  =1 where ISCHECKED  =@num
    enb 
    else
    begin
     update Tab set ISCHECKED  =0 where ISCHECKED  =@num
    end
      

  2.   

    这是不行的
    SQL:叫Structured Query Language:结构化查询语言,主要是用来筛选数据的。在处理具体的业务逻辑的时候很吃力!
      

  3.   

    表tab中有主键列ID
    update tab set ISCHECKED = convert(int,replace('01',ISCHECKED,'')) 
    where ID = 要修改记录的ID值
      

  4.   

    create procedure proc_update
    ASupdate tableName
    set ISCHECKED=(case ISCHECKED when 0 then 1 else 0 end)
    --where [id]=go
      

  5.   

    alter procedure proc_update
    ASupdate tableName
    set ISCHECKED=(case ISCHECKED when 0 then 1 when 1 then 0 else ISCHECKED end)
    --where [id]=go
      

  6.   

    很少在sql里面做这样判断,试一下看这样行不行。