declare @testTypeCode int
set @testTypeCode = 4
declare @tbl  table (
	data varchar(100)
)
declare @subjectCode int
declare @subjectName varchar(100)
DECLARE cur CURSOR FOR SELECT SubjectCode, SubjectName from dat_Subjects where TestTypeCode=@testTypeCode

OPEN cur

FETCH NEXT FROM cur INTO @subjectCode, @subjectName
WHILE @@FETCH_STATUS = 0
BEGIN
	insert into @tbl(data) values ('*' + @subjectName)
	insert into @tbl(data) 
	select ExamDate + '=' + CAST(ExamGlobalID as varchar(10)) from dat_Exams where SubjectCode=@subjectCode and TestTypeCode=@testTypeCode
	insert into @tbl(data) values ('')
	
	FETCH NEXT FROM cur INTO @subjectCode, @subjectName
end

close cur
DEALLOCATE cur

select * from @tbl