sqlserver的sql语句里能在where条件里用case when吗,如果可以,请给个简单的例子。
2013-04-15
展开全部
1>
2> SELECT * FROM t_test_sub;
3> GO
id main_id value
----------- ----------- ----------
2 12 TWOTWO
11 21 AAAA
12 22 BBBB
13 NULL CCCC
14 NULL DDDD
15 NULL EEEE
(6 行受影响)
1> UPDATE t_test_sub set value = 'test' WHERE case when id>10 then 1 else 0 end
= 1
2> go
(5 行受影响)
1> SELECT * FROM t_test_sub;
2> go
id main_id value
----------- ----------- ----------
2 12 TWOTWO
11 21 test
12 22 test
13 NULL test
14 NULL test
15 NULL test
(6 行受影响)
1>
2> SELECT * FROM t_test_sub;
3> GO
id main_id value
----------- ----------- ----------
2 12 TWOTWO
11 21 AAAA
12 22 BBBB
13 NULL CCCC
14 NULL DDDD
15 NULL EEEE
(6 行受影响)
1> UPDATE t_test_sub set value = 'test' WHERE case when id>10 then 1 else 0 end
= 1
2> go
(5 行受影响)
1> SELECT * FROM t_test_sub;
2> go
id main_id value
----------- ----------- ----------
2 12 TWOTWO
11 21 test
12 22 test
13 NULL test
14 NULL test
15 NULL test
(6 行受影响)
1>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询