/* To concatenate several binary values into one image field: */
create table #Bin ( SegmentID int IDENTITY ( 1 , 1 ) , Segment varbinary(2) )
insert #Bin values (0x11)
insert #Bin values (0x22)
select * from #Bin
go
declare @imageptr varbinary(16), @segmentid int, @segment varbinary(16)
create table #AllBin ( Segments image null )
-- Get valid pointer first
insert #AllBin values ( 0x0 )
select @imageptr = TEXTPTR( Segments ) from #AllBin
-- Set data to null
update #AllBin set Segments = null

select @segmentid = -1
while(1=1)
begin
    select @segmentid = min(segmentid)
    from #Bin
    where segmentid > @segmentid
    if @segmentid is null break

    select @segment = segment from #Bin where segmentid = @segmentid

    updatetext #AllBin.Segments @imageptr null 0 @segment
end
select * from #AllBin
go
drop table #Bin
drop table #AllBin
go
This page was last updated on May 01, 2006 04:28 PM.