I have a question. I am working on something based on the information I got from this forum.
I am using the sample I found and modifying it a little to get the results I want..
--TABLE--
Create table test
(PersonID varchar(2),
Degree varchar(10))
insert into test values ('55', 'MD')
insert into test values ('55', 'PhD')
insert into test values ('55', 'RN')
insert into test values ('60', 'MD')
insert into test values ('60', 'PhD')
--SO FAR THIS IS WHAT I HAVE
declare @DegName varchar(50)
declare @Sql nvarchar(4000)
declare c cursor FAST_FORWARD for
select distinct degree from test order by degree
open c
fetch next from c into @DegName
set @Sql = 'select personid, '
while @@Fetch_Status = 0
begin
set @Sql = @Sql + '+ Min(Case when Degree = ''' + @DegName + ''' then
degree end) + ''; '' '
fetch next from c into @DegName
end
close c
deallocate c
set @Sql = @Sql + 'as Degree'
print @sql
set @Sql = @Sql + ' from test group by PersonId '
print @sql
exec (@sql)
--DESIRED RESULTS--
PersonID Degree
55 MD; PhD; RN
60 MD; PhD
--ACTUAL RESULTS--
PersonID Degree
55 MD; PhD; RN
60 NULL <--- I need help in changing this to MD; PhD
I am only using SQL Server 2000.. I am open to other methods as long as the Desired result is achieved