June 4, 2012

sp_MStestbit (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_MStestbit(varbinary @bm
, smallint @coltotest)

MetaData:

 create procedure sys.sp_MStestbit  
@bm varbinary(128),
@coltotest smallint
AS
declare @word smallint
declare @bit smallint
declare @mask binary(2)
declare @mval int
declare @oldword binary(2)

if @coltotest < 1 return 0

SELECT @word = 1 + FLOOR((@coltotest -1)/16)

SELECT @bit = (@coltotest -1) % 16

SELECT @mval = POWER(2, @bit)
SELECT @mask = convert( binary(2), unicode( substring( convert( nchar(2), convert( binary(4), @mval ) ), 2, 1 ) ) )

SELECT @oldword = convert( binary(2), SUBSTRING( convert( nvarchar(64),@bm), @word, 1) )
IF @oldword IS NULL return 0

return convert( smallint, @oldword ) & convert( smallint, @mask )

No comments:

Post a Comment

Total Pageviews