Print Column Names for Table in Another Database
You were almost there with your second answer - you just need to ensure you're selecting columns from the correct sys.columns table

declare @ColumnList varchar(max) = 
(select STUFF((
SELECT ', 
    '    
+ QUOTENAME(c.name) 
FROM DatabaseB.sys.columns c 
where c.object_id = object_id('DatabaseB.dbo.Customer')
FOR XML PATH(''), TYPE).value('.','nvarchar(max)'),1,2,''))

print @ColumnList


The above works for me, adding the DB reference into sys.columns for DatabaseB.