0

I am having difficulty retrieving a comma separated list from MSAccess using SQL. It is very easy to do with SQL Server and I have accomplished it there. But the MSAccess solution seems to elude me.

DECLARE @EmployeeList varchar(100)

SELECT @EmployeeList = COALESCE(@EmployeeList + ', ', '') + 
       CAST(Emp_UniqueID AS varchar(5))
FROM SalesCallsEmployees
WHERE SalCal_UniqueID = 1

SELECT @EmployeeList

http://www.sqlteam.com/article/using-coalesce-to-build-comma-delimited-string

Has anybody accomplished this using MS Access or am I just doomed to never getting lists like this through SQL?

4
  • 3
    The SQL above has no equivalent in Jet/ACE. There is no option with Jet/ACE other than walking the recordset and concatenating the string. Nov 11, 2010 at 20:45
  • 1
    @David-W-Fenton I am not sure what you mean by this in that I have previously replied that it is possible to SELECT Field & ",", which is certainly not the equivalent of the above, but I do not think it could be called "walking the recordset", either.
    – Fionnuala
    Nov 11, 2010 at 21:41
  • 2
    Well, it doesn't do what has been requested, no? Your solution can only concatenate columns within a single row, but what is needed is concatenation of values in different rows (at least, insofar as I understand the question and the COALESCE()-based answer). Nov 12, 2010 at 18:34
  • Yes David you are correct, I want to take a list and turn it into a comma seperated column. Nov 12, 2010 at 21:53

1 Answer 1

1

You can select the fields (columns) one by one:

SELECT ID & ",", Other & "," 
FROM table
2
  • I need to select the same column. So i do "Select Name From Categories Where Category.ParentID = 1', not sure if this works in that scenario. Nov 11, 2010 at 20:39
  • That will work fine, the where and select are two separate statement.
    – Fionnuala
    Nov 11, 2010 at 20:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.