May 13, 2008 at 12:25 pm
Hello,
If I have a table structured like this:
[font="Courier New"]Company Employee
--------- ------
IBM Ron
IBM Rachel
Microsoft John
Microsoft Jane[/font]
and I want my results to look like this:
[font="Courier New"]
Company EmployeeList
--------- -------------
IBM 'Ron Rachel'
Microsoft 'John Jane'[/font]
Any ideas on how to accomplish this? I know how to do this for a single company. i.e.:
declare @EmployeeList varchar(100),
@ThisCompany varchar(10)
set @EmployeeList = ''
set @ThisCompany = 'IBM'
select @EmployeeList = @EmployeeList + Employee + ' ' where Company = @ThisCompany
select @ThisCompany, @EmployeeList
But not for all the companies that appear in the table.
May 13, 2008 at 12:29 pm
You may try to use cursor.
May 13, 2008 at 12:33 pm
Well I was trying to be a "good boy" and not use a cursor. Is it not possible without using a cursor?
May 21, 2008 at 3:54 pm
Let me see whether or not I can help the "good boy" :hehe:
SELECT Company, MAX(Employee) FROM yourTable GROUP BY Company
May 21, 2008 at 9:40 pm
I don't believe that works the way the OP posted... that will only give 1 employee name per company.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 21, 2008 at 9:41 pm
wgarces,
See the following article... it covers this type of concatenation and a couple of related pitfalls to avoid...
http://www.sqlservercentral.com/articles/Test+Data/61572/
--Jeff Moden
Change is inevitable... Change for the better is not.
May 22, 2008 at 9:57 am
Thanks Jeff. I will check out that article.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply