日期:2014-05-18 浏览次数:20490 次
declare @t table(字段1 int,字段2 int, 字段3 int, 字段4 int, 字段5 int, 字段6 int,字段7 int)
insert @t select 1, 3, 5, 6, 16, 30, 33
insert @t select 4, 5, 8, 9, 12, 34, 35
select
*,
[字段8]=(select rtrim(sum(case when col%2=1 then 1 else 0 end))+':'+rtrim(sum(case when col%2=0 then 1 else 0 end))
from (select 字段1 as col union all select 字段2 union all select 字段3 union all select 字段4
union all select 字段5 union all select 字段6 union all select 字段7)t )
from
@t
(所影响的行数为 1 行)
(所影响的行数为 1 行)
字段1 字段2 字段3 字段4 字段5 字段6 字段7 字段8
----------- ----------- ----------- ----------- ----------- ----------- ----------- -------------------------
1 3 5 6 16 30 33 4:3
4 5 8 9 12 34 35 3:4
(所影响的行数为 2 行)
declare @t table(a int,b int, c int, d int, e int, f int,g int) insert @t select 1, 3, 5, 6, 16, 30, 33 insert @t select 4, 5, 8, 9, 12, 34, 35 select *, h=rtrim( (case when a%2=0 then 1 else 0 end) +(case when b%2=0 then 1 else 0 end) +(case when c%2=0 then 1 else 0 end) +(case when d%2=0 then 1 else 0 end) +(case when e%2=0 then 1 else 0 end) +(case when f%2=0 then 1 else 0 end) +(case when g%2=0 then 1 else 0 end) )+':'+ rtrim( (case when a%2=1 then 1 else 0 end) +(case when b%2=1 then 1 else 0 end) +(case when c%2=1 then 1 else 0 end) +(case when d%2=1 then 1 else 0 end) +(case when e%2=1 then 1 else 0 end) +(case when f%2=1 then 1 else 0 end) +(case when g%2=1 then 1 else 0 end) ) from @t /* -------------------------- 1 3 5 6 16 30 33 3:4 4 5 8 9 12 34 35 4:3 */