0

I'm need of creating a table whose columns names are containeid in another table, very much like this Create a table with column names derived from row values of another table , but I could not make it work on MSSQL since it was designed for MySQL and MSSQL does not support Group Concat.

Ps. I could not comment on the original post due to StackOverflow commentary limitations.

usuario042
  • 31
  • 4

1 Answers1

0

After some tweaking around I achieved a partial solution, the code below does create a table with column names of another table.

DECLARE @sql varchar (2000)
SET @Sql = 'create table temp_itens('
SELECT @Sql += <ColumnNamesColumnFromAnotherTable> + ' VARCHAR(100) NOT   NULL, '
FROM <table> 
SET @sql = LEFT(@sql , len (@sql) - 1 ) + ')'
EXEC(@sql)
usuario042
  • 31
  • 4
  • Now I'm considering a script to include multiple variations of that column names based on a series of fields in the table. – usuario042 Jan 29 '15 at 17:09