_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › 覓語Bit一磯語

Contents

1 覓語
2
3 覲旧″伎 伎螳 覘蟾?
4 るジ


1 覓語 #

る 磯殊 覩語 讌覓語 殊. 蠍一覲螻 Bit一一 蟯 覓語襦 DBMS れ 豬渚 覿覿願鍵 覓語 覓語襯 企慨. 讌覓語 れ螻 螳. (覓: http://www.devpia.com/Maeul/Contents/Detail.aspx?BoardID=41&MAEULNo=17&no=4619&ref=4619)

語 MS SQL .. '1001' , '0101' 企 襦 4襴 覓語企 2讌 覓語襯... OR 觜 一一 伎 襦 4襴 覓語伎 襷れ 伎狩. 襯 れ 覓語 '1001' 螻 '0101' 襯 OR 觜 一壱.. '1101' 企朱 覓語襯 觸伎 蟇一.. 貎朱Μ襯 覈詞蟆伎.. 覿襴暑.
* 讌覓語 給 語 蟆企. るジ 襭 覲企 蟆 蟒 . 蠎 企Ν讌伎 るジ 襭 覲願鍵 覦.

2 #

/*
drop table #temp
create table #temp(seq int, a varchar(30), b varchar(30))
insert #temp values(1, '1001' , '0101')
insert #temp values(2, '10011' , '01011')
*/

with dumy(num)
as
(
        select 0 num
        union all
        select num + 1 from dumy
        where num + 1 <= 30
),
rs (seq, a, b, rs)
as
(
	select
		a.seq
	,	a.a
	,	a.b
	,	b.rs
	from #temp a
		cross apply (
			select 
				case 
					when '1' in (substring(a.a, num+1, 1), substring(a.b, num+1, 1)) then '1'
					else '0'
				end rs
			from dumy
			where num <= case when len(a.a) > len(a.b) then len(a.a) else len(a.b) end  - 1
		) b
)
select distinct
	seq
,	a
,	b
,	(select cast(rs as varchar(100)) as 'text()' 
	 from rs where a.seq = seq for xml path('')) [a | b]
from rs a


3 覲旧″伎 伎螳 覘蟾? #

企ゼ 覲企 譬 覲旧″る 螳 蟆企. 螳 覲願鍵 伎 蟆 . 覃 覓語 豌願 DBMS 轟煙 螻ろ讌 蠍 覓語企. 危襴貅伎 Bit一一 襷 暑. 覓朱 朱朱 DBMS Bit一磯 暑. '1101'螻 螳 覓語伎 13企朱 襯 蠏語 Bit一一 る 覲旧″讌 訖 觜 覈 豌覦(伎覃 覈 襷覦 伎) 渚 蟆企. 讀, れ螻 螳 蟆企.

2讌10讌
110113
01015

讀, 13, 5 螳 企 SQL Server OR Bit一一 れ螻 螳 蟆企.

select 13|5

蟆郁記 り[1] 覓語. り 觜(讌覲伎 ) 觜蟲覃? 襷 給旭 る 蟆企.

4 るジ #

--drop table #temp
create table #temp(id int, col1 varchar(30), col2 varchar(30))
insert #temp values(1, '1001' , '0101')
insert #temp values(2, '10011' , '01011')

;with dummy(seq)
as
(
        select 1 seq
        union all
        select seq + 1 from dummy
        where seq + 1 <= 30
), result
as
(
    select 
        a.id
    ,   a.col1
    ,   a.col2
    ,   sign(convert(tinyint, substring(col1, seq, 1)) + substring(col2, seq, 1)) rs
    from #temp a
        cross join dummy b
    where b.seq <= len(a.col1)
)
select 
	id
,	x [col1 | col2]
from #temp a
    cross apply (
        select (
            select cast(rs as varchar(100)) as 'text()' 
	        from result where a.id = id for xml path('')) x
    ) b
----
   [1]  誤壱伎 り
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:53

磯ゴ 覯 讌 覈詩 譬 讌螳 . (襴ろ)