0

i'm trying to migrate a mysql view from mysql to sql server 2008, but there is a funcion called "group_concat" and i cant emulate it in sql server.

Here is the code

select 
permiso.ID AS ID,replace(
group_concat(cuerpo_legal.descripcion, _utf8' ',
documento_legal.NUM_CUERPO_LEGAL, _utf8' / ',
documento_legal.ANNO_CUERPO_LEGAL separator ',')
,_utf8',', _utf8' ; ') AS cuerpo_legal
from
(((permiso
join permiso_doc_legal ON ((permiso_doc_legal.ID_PERMISO = permiso.ID)))
join documento_legal ON ((documento_legal.ID = permiso_doc_legal.ID_DOCUMENTO_LEGAL)))
join cuerpo_legal ON ((cuerpo_legal.id_cuerpo_legal = documento_legal.ID_CUERPO_LEGAL)))
group by permiso.ID

I've tried diferent ways and searched here in stackoverflow but none one works

Thanks!

unknown
  • 4,859
  • 10
  • 44
  • 62
Herman Zun
  • 471
  • 1
  • 6
  • 21
  • Similar question asked and answered using FOR XML path and STUFF. http://stackoverflow.com/questions/17591490/how-to-make-a-query-with-group-concat-in-sql-server not nearly as clean; but aside from this and possible use of a CTE I can't think of another way to do it. – xQbert Mar 14 '14 at 18:24
  • If you want to get really deep in it, you can create a custom aggregation function with SQL CLR and use it exactly like you are asking. See this link http://msdn.microsoft.com/en-us/library/ms182741(v=sql.105).aspx – Kevin Suchlicki Mar 14 '14 at 19:03

0 Answers0