sql server - how to convert column values into comma seperated row vlaues -
i have table values
fktable_name fkcolumn_name pkcolumn_name table1 column1 column1 table1 column2 column2 table2 column1 column1 table2 column2 column2
how need convert into
fktable_name fkcolumn_name pkcolumn_name tablel1 column1,column2 column1,column2 table12 column1,column2 column1,column2
basically, trying comma seperated columns group table name.
thanks
here's working query on db
select distinct table_name, stuff((select ','+data_type information_schema.columns b b.table_name=a.table_name xml path(''),type).value('.[1]','nvarchar(max)'),1,1,'') data_types, stuff((select ','+column_name information_schema.columns b b.table_name=a.table_name xml path(''),type).value('.[1]','nvarchar(max)'),1,1,'') column_names information_schema.columns
and here query
select distinct fktable_name, stuff((select ','+fkcolumn_name tbl b b.fktable_name=a.fktable_name xml path(''),type).value('.[1]','nvarchar(max)'),1,1,'') fkcolumn_names, stuff((select ','+pkcolumn_name tbl b b.fktable_name=a.fktable_name xml path(''),type).value('.[1]','nvarchar(max)'),1,1,'') pkcolumn_names tbl
Comments
Post a Comment