SQL问题,小白求大神赐教,在线等!
有一个文本属性的字段CKS(仓库数),但是内容是数字(方便系统实现),然后就是状态字段STAT,如果【CKS】仓库数=0,【STAT】状态值为‘空’,否则值为‘有货’。
这怎么用sql 语句来写?用case when 可以吗?
------解决方案--------------------select case when cast(CKS as int)=0 then ‘空’ else ‘有货’ end as stat
from 表
------解决方案--------------------select case
when cast(CKS as int)=0 then N‘空’
else N‘有货’ end as stat
from TableName
Good Luck!
------解决方案--------------------
update [表名]
set STAT=case CKS when '0' then '空'
else '有货' end
------解决方案--------------------select case
when cast(CKS as int)=0 then N‘空’
else N‘有货’ end as stat
from TableName