create procedure sys.sp_MSgetcolumnlist(
@pubid uniqueidentifier,
@column_list nvarchar(max) OUTPUT,
@source_objid int,
@guid_alias sysname=NULL
)
AS
/*
** if it is not vertically partitioned, then get all columns
** else get the column list as given in columns of dbo.sysmergearticles
*/
declare @bitset int
declare @columns varbinary(128)
declare @setcolcnt int
declare @colcnt int
declare @colname nvarchar(258)
declare @colid int
declare @unqual_sourcename sysname
declare @qual_sourcename nvarchar(258)
if @guid_alias is NULL
begin
select @unqual_sourcename=object_name(@source_objid)
select @qual_sourcename = QUOTENAME(@unqual_sourcename)
end
else
select @qual_sourcename = @guid_alias
select @columns = columns from dbo.sysmergearticles where objid = @source_objid and pubid=@pubid
select @column_list = ''
select @setcolcnt = 0
select @colcnt = count(*) from sys.columns where object_id = @source_objid
declare collist CURSOR LOCAL FAST_FORWARD FOR
select name, column_id from sys.columns where object_id = @source_objid order by column_id ASC
FOR READ ONLY
open collist
fetch collist into @colname, @colid
WHILE (@@fetch_status <> -1)
BEGIN
exec @bitset = sys.sp_MStestbit @columns, @colid
-- if @bitset<>0
if @bitset<>0 or @columns is null or @columns = 0x00
begin
select @colname = QUOTENAME(@colname) --previously we use rowguidcol to replace 'rowguid'
if @column_list='' --which can cause problems and is not necessary.
select @column_list = @qual_sourcename + '.' + @colname
else
select @column_list = @column_list + ', ' + @qual_sourcename + '.' + @colname
select @setcolcnt = @setcolcnt + 1
end
fetch next from collist into @colname, @colid
END
close collist
deallocate collist
if @setcolcnt = @colcnt
select @column_list = ' * '