更新字段

update  table set table.field=

(

  case when 条件

  then 值1

  else 值2 end  

)

where 条件

如:update BM_TrainingPeriod set IsValid=(
                         case when exists(select 1 From BM_TrainingGroup y where BM_TrainingPeriod.id=y.TrainingPeriodid and IsValid=1)
                            then 1
                            else 0
                            end
                        )
                        where id=@TrainingPeriodID

原文地址:https://www.cnblogs.com/dengjd/p/3358550.html