----------------------------------------------------------------
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-04-08 13:05:22
-- Version:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
-- Apr 2 2010 15:48:46
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([col1] nvarchar(2),[col2] nvarchar(2),[col3] int)
insert [huang]
select 'a','t',1 union all
select 'a','s',2 union all
select 'a','b',1 union all
select 'b','t',2 union all
select 'b','b',3 union all
select 'b','s',4
--------------生成数据--------------------------select col1,col2,CASE WHEN col1='a' AND col2='t' THEN 0 ELSE col3 END col3
from [huang]
----------------结果----------------------------
/*
col1 col2 col3
---- ---- -----------
a t 0
a s 2
a b 1
b t 2
b b 3
b s 4
*/
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-04-08 13:05:22
-- Version:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
-- Apr 2 2010 15:48:46
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([col1] nvarchar(2),[col2] nvarchar(2),[col3] int)
insert [huang]
select 'a','t',1 union all
select 'a','s',2 union all
select 'a','b',1 union all
select 'b','t',2 union all
select 'b','b',3 union all
select 'b','s',4
--------------生成数据--------------------------select col1,col2,CASE WHEN col1='a' AND col2='t' THEN 0 ELSE col3 END col3
from [huang]
----------------结果----------------------------
/*
col1 col2 col3
---- ---- -----------
a t 0
a s 2
a b 1
b t 2
b b 3
b s 4
*/
update 表 set col3=0 where col1 = a and col2 = t
update 表 set col3=0 where col1 = 'a' and col2 = 't'