sql server column value to be converted in comma seperated -
before question marked duplicate, know how can done without doing declare statement want within query
like have query
select distinct costcenterid,costcentername,costcenterdesc,contactid,expirationdate,portal_id, active,customername,branchid,id costcenter cc inner join branchesinportals bp on bp.portalid = cc.portal_id
the branchid
, id
fields have different values other rows have same values if remove , distinct works good, 1 record
i want should return me 1 record , combine columns branchid
, id
comma separated values
i tried looking link seems working how can integrate link code query
http://www.codeproject.com/tips/635166/sql-column-values-as-comma-separated-string
you can use for xml
solve problem. here list of column names (you can run in sql server database):
select stuff(( select ', ' + cast(column_name varchar(max)) information_schema.columns xml path('') ), 1, 2, '');
here how have one-to-many value set show up:
select distinct c1.table_name, stuff(( select ', ' + cast(column_name varchar (max)) information_schema.columns c2 c1.table_name = c2.table_name xml path ('') ), 1, 2, '') columns information_schema.columns c1
here output master database tables , columns:
Comments
Post a Comment