Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSget_shifted_colv1

  No additional text.


Syntax
create procedure sys.sp_MSget_shifted_colv1
(
        @cols_being_dropped varbinary(128), -- cols being dropped
        @input_colv1 varbinary(2953),           -- input colv1
        @output_colv1 varbinary(2953) output -- output colv1
)
as
begin
    set @output_colv1 = NULL

    declare @countval int, @i smallint, @colidx smallint,
            @colidxbits varbinary(2), @restcolv1 varbinary(10), @survivecolvs int

    -- prepare conversion table
    declare @length int, @count int, @pos int, @retcode int
    create table #tmp_cols_being_dropped
    (
            colid int,
            count int
    )
    -- bit by bit op
    set @length=datalength(@cols_being_dropped)*8
    set @count=1
    set @pos=1
    while @pos<=@length
    begin
            exec @retcode = sys.sp_MStestbit @cols_being_dropped, @pos
            if @retcode<>0
            begin
                    insert #tmp_cols_being_dropped (colid, count) values (@pos, @count)
                    set @count=@count+1
            end
            set @pos=@pos+1
    end

    if not exists (select * from #tmp_cols_being_dropped)
            return 1

    -- byte by byte op
    set @survivecolvs=0
    set @i= 0
    while (@i < DATALENGTH(@input_colv1)/12)
    begin
        set @colidx= cast(substring(@input_colv1, @i*12+2,1) as smallint)
        set @colidx= @colidx*256 + cast(substring(@input_colv1, @i*12+1,1) as smallint)
        set @restcolv1=substring(@input_colv1, @i*12+3,10)
        set @colidx=@colidx+1 -- change to colid base as 1

        -- convert @colidx
        if exists (select * from #tmp_cols_being_dropped where colid=@colidx)
                goto NEXT

        -- we have one surviving colv now
        set @survivecolvs=@survivecolvs+1
        if DATALENGTH(@output_colv1) =0 or @output_colv1 is null
            set @output_colv1=convert(binary(12), replicate(12, 0x00)) --0x000000000000000000
        else
            set @output_colv1=@output_colv1+convert(binary(12), replicate(12, 0x00))

        set @countval=NULL
        select @countval=count from #tmp_cols_being_dropped where colid in
                (select min(colid) from #tmp_cols_being_dropped where @colidx>colid)

        -- this is colv not affected by dropping cols
        if @countval is NULL
        begin
                set @output_colv1=convert(varbinary(2953), stuff(@output_colv1, (@survivecolvs-1)*12+1, 12, substring(@input_colv1, @i*12+1,12)))
        end
        -- this colv needs to have its colidex adjusted
        else
        begin
            set @colidx=@colidx-@countval-1 -- change back to colidex base as 0

            set @colidxbits=0x0000
            set @colidxbits=convert(varbinary(2), stuff(@colidxbits, 1, 1, convert(binary(1), @colidx%256)))
            set @colidxbits=convert(varbinary(2), stuff(@colidxbits, 2, 1, convert(binary(1), @colidx/256)))

            set @output_colv1=convert(varbinary(2953), stuff(@output_colv1, (@survivecolvs-1)*12+1, 2, @colidxbits))
            set @output_colv1=convert(varbinary(2953), stuff(@output_colv1, (@survivecolvs-1)*12+3, 10, @restcolv1))
        end
NEXT:
        set @i= @i+1
    end

    if DATALENGTH(@output_colv1)=0 or @output_colv1 is null
            set @output_colv1=0xFF
    else
            set @output_colv1=@output_colv1+0xFF
end

 
Last revision 2008RTM
See also

  sp_MSdrop_rlrecon (Procedure)
sp_repldropcolumn (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash