December 14, 2006 at 3:21 am
Is it possible to place all the results of a select statement into one line,
eg Select surname from stafflist
and the results would appear like : xyz,abc,stu.....
The table I am using is dymanic and I can not think of a simple solution to do the above query
December 14, 2006 at 3:36 am
ya, its possible
DECLARE @StaffList varchar(100)
SELECT @StaffList = COALESCE(@StaffList + ', ', '') + Surname
FROM StaffList order by Surname asc
SELECT @StaffList
When @StaffList is NULL (the first row processed), it returns an empty string. On subsequent rows, it concatenates the @StaffList value with a comma and the current Surname.
December 14, 2006 at 4:00 am
Thanks a million, that worked
December 14, 2006 at 4:12 am
Its ok.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply