create procedure sys.sp_MSget_map_position
@primary_key_bitmap varbinary(4000) = null,
@index int,
@colpos sysname = NULL output,
@art_col int = NULL output
as
declare @this_col int
declare @num_keys int
declare @num_cols int
select @this_col = 1
select @num_keys = 0
select @num_cols = datalength(@primary_key_bitmap) * 8
select @colpos = null
select @art_col = null
while @this_col <= @num_cols
begin
if (substring(@primary_key_bitmap, 1 + (@this_col-1) / 8 , 1) &
power(2, (@this_col-1) % 8 )) <> 0
begin
select @num_keys = @num_keys + 1
if @num_keys = @index
begin
select @art_col = @this_col
select @colpos = 'c' + convert(sysname, @this_col)
break
end
end
select @this_col = @this_col + 1
end