4>
5> CREATE FUNCTION dbo.bitwise_or
6> (
7> @arg1 varbinary(8),
8> @arg2 varbinary(8)
9> ) RETURNS varbinary(8)
10> AS
11> BEGIN
12>
13> DECLARE
14> @result AS varbinary(8),
15> @numbytes AS int,
16> @curpos AS int
17> SET @result = 0x
18> SET @numbytes = DATALENGTH(@arg2)
19> SET @curpos = 1
20> WHILE @curpos <= @numbytes
21> BEGIN
22> SELECT
23> @result = @result + CAST(SUBSTRING(@arg1, @curpos, 1) |
24> CAST(SUBSTRING(@arg2, @curpos, 1)
25> AS tinyint)
26> AS binary(1))
27> SET @curpos = @curpos + 1
28> END
29>
30> RETURN @result
31> END
32> GO
1> GRANT EXECUTE ON dbo.bitwise_or TO public
2> GO
1>
2> SELECT dbo.bitwise_or(0x00000001000000010000000100000001,
3> 0xffffffffffffffffffffffffffffffff)
4>
5> drop function dbo.bitwise_or
6> GO
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
----------------------------------
0xFFFFFFFFFFFFFFFF
(1 rows affected)
1>
2>