For SQL Server you can use FOR XML PATH() statement to achieve that.