2

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()?

3

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

will test this out and confirm back.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.