日期:2014-05-17 浏览次数:20713 次
declare @EMP table (ID int,Dj varchar(2),money varchar(8)) insert into @EMP select 1,'','' union all select 2,'2','10' union all select 3,'3','100' union all select 4,'4','0' union all select 5,'5','80' --原数据 select * from @EMP /* ID Dj money ----------- ---- -------- 1 2 2 10 3 3 100 4 4 0 5 5 80 */ UPDATE @EMP SET DJ=CASE WHEN DJ='' THEN '1' ELSE DJ END, MONEY=(CASE WHEN MONEY+0<1 and MONEY<>'' THEN CONVERT(VARCHAR(10),MONEY+80) WHEN MONEY='' THEN CONVERT(VARCHAR(10),MONEY+100) ELSE MONEY END) --更新后 SELECT * FROM @EMP /* ID Dj money ----------- ---- -------- 1 1 100 2 2 10 3 3 100 4 4 80 5 5 80 */
------解决方案--------------------
叶子正解!
------解决方案--------------------
to maco_wang:
money为0的时候为什么是冲了80?
------解决方案--------------------
一楼正解!!!
------解决方案--------------------
declare @EMP table (ID int,Dj varchar(2),money varchar(8)) insert into @EMP select 1,'','' union all select 2,'2','10' union all select 3,'3','100' union all select 4,'4','0' union all select 5,'5','80' UPDATE @EMP SET [money] = CASE WHEN LEN(ISNULL([money],'')) = 0 OR [money] < 1 THEN 100 ELSE [money] END, Dj = CASE WHEN LEN(ISNULL(Dj,'')) = 0 THEN '1' ELSE Dj END; SELECT * FROM @EMP; ID Dj money ----------- ---- -------- 1 1 100 2 2 10 3 3 100 4 4 100 5 5 80 (5 row(s) affected)
------解决方案--------------------