There are several cases in SQL where it's necessary to update a variable once per row in a result, accumulating all of the changes together.
A sample of code that works in SQL Server:
DECLARE @InvoicesList VARCHAR(1024) SELECT @InvoicesList = COALESCE(@InvoicesList + ', ', '') + pay.[InvoiceNumber] FROM Payments AS pay WHERE pay.Order_id = @orderId ORDER BY pay.[InvoiceNumber] RETURN @InvoicesList
VistaDB presently returns the last column value. Please vote this up!