declare @CPTCode varchar(50)
declare @Sql nvarchar(4000)
declare c cursor FAST_FORWARD for
select distinct CPT from TblCPTCodes order by CPT
open c
fetch next from c into @CPTCode
set @Sql = 'select MembID '
while @@Fetch_Status = 0
begin
set @Sql = @Sql + ', Min(Case when CPT = ''' + @CPTCode + ''' then
CPT end) as ''' + @CPTCode + ''' '
fetch next from c into @CPTCode
end
close c
deallocate c
set @Sql = @Sql + ' from TblCPTCodes group by MemID'
print @sql
exec (@sql)
|