数据骑兵

导航

狀態多選

--狀態多選
--如果有狀態為A,B,C,D,E,F等區域,可多選.
--則可用編碼A:1,B:2,C:4,D:8,E:16,F:32,G:64,m選擇A,D則為1+8=9,n選則B,C則為2+4=6
--檢查m及n之所有選擇
select 9|7
--檢查m及n之交集
select 9&7
--如果判斷其所在區域可用
DECLARE @I int
set @I=9&7
select 'A' where @I&1=1    --查是否為A
select 'B' where @I&2=2    --查是否為B
select 'C' where @I&4=4    --查是否為C
select 'D' where @I&8=8    --查是否為D
select 'E' where @I&16=16    --查是否為E
select 'F' where @I&32=32    --查是否為F
select 'G' where @I&64=64    --查是否為G
--實例
select * from (
select 'NO' no,26 vaule
) a join (
select 1 code,'A' name
union all select 2 code,'B' name
union all select 4 code,'C' name
union all select 8 code,'D' name
union all select 16 code,'E' name
union all select 32 code,'F' name
) b
on a.vaule&b.code=b.code

posted on 2007-11-15 14:51  数据骑兵  阅读(148)  评论(0编辑  收藏  举报