Hafsa Mushtaq
Hafsa Mushtaq

Reputation: 3781

Conversion of MySQL queries to SQl Server queries in drupal application

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

Answers (1)

Daniela
Daniela

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

Related Questions