T-SQL 如果该字段为空,就显示指定值,但不更改数据库中的值

 ------先查询数据库中的值

select ownerCode from MB where Id=1

--如果ownerCode字段为空,就显示5,但不更改数据库中的记录
if((select ownerCode from MB where Id=1 )='')
select ownerCode=5 from MB where Id=1
else --如果ownerCode字段不为空就显示该值
select ownerCode from MB where Id=1


  

 ------查询数据库中的值是否改变(结果没有变)
   select ownerCode from MB   where Id=1


猜你喜欢

转载自blog.csdn.net/lwbjyl/article/details/6401857