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

来源:互联网 发布:城市规划就业 知乎 编辑:程序博客网 时间:2024/04/29 01:25

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

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

 


原创粉丝点击