日期:2014-05-17 浏览次数:20728 次
--> 测试数据:[test]
if object_id('[test]') is not null
drop table [test]
create table [test](
[order] varchar(4),
[num] int,
[status_flag] int
)
insert [test]
select 'r001',5,1 union all
select 'r002',6,0 union all
select 'r003',7,0 union all
select 'r004',8,1
if object_id('[a]') is not null
drop table a
create table a(
[order] varchar(4),
[num] int,
[status_flag] int
)
go
insert a
select [order],
case when [status_flag]=0 then -[num] else [num] end,[status_flag]
from test
go
select * from a
/*
order num status_flag
-----------------------------------
r001 5 1
r002 -6 0
r003 -7 0
r004 8 1
*/
------解决方案--------------------
插入的时候用case判断一下就行了