I have a store procedure that is supposed to generate an XML file based on data available in a table. If there are data in all the fields, it work fine. However, if there are no date in one or more of the fields, it does not create the xml. It return null instead. I started debugging it and noticed that @part1 has the correct value, part2 has the correct value, and part3 has the correct value. Once I concatenate them, I noticed part1 is now null. What am I missing here?
select @part1 = '<Students>';
@part2 ='<NumberOFCourse>'+isnull(convert(varchar,(select NumberOFCourse from Courses)), 0)+'</NumberOFCourse>' ;
select @part3 = '<NumberOFSemesterCredit>'+isnull(convert(varchar,(select NumberOFSemesterCredit from Courses)), 0)'</NumberOFSemesterCredit>' +
'</Students>';
select @part1 += @part2 + @part3