Reputation: 3781
I am migrating my database from MySQl to SQL Server. My app is built on top of drupal. I am not able to convert the following code to its SQL Server equivalent :
addExpression("GROUP_CONCAT(qa.answer SEPARATOR ',') ", 'lookingfordetails')
.
What is the SQL Server equivalent of GROUP_CONCAT()
and how do I implement it in addExpression()
?
Upvotes: 2
Views: 203
Reputation: 454
I don't know if this works because I can't test it, but I suggest something like this:
$expression = 'STUFF((SELECT ',' + answer as lookingfordetails FROM table FOR XML PATH('')),1 ,1 ,'')';
$query->addExpression($expression);
I think you could see group_concat conversion to other databases: http://www.sqlines.com/mysql/functions/group_concat
Upvotes: 1