The problem is here:
[Composite Score Eligible ] [nvarchar](255) NULL,
[Composite Score] [nvarchar](255) NULL,
[Composite Score PGS Percentage] [nvarchar](255) NULL,
[coremeasure] [bit] NULL,
[pediatric] [bit] NULL
These 5 fields at the end do not fit the pattern of the others.
Remember we are just pulling columns by numbers, so it is going to try to put [Composite Score Eligible ] and [Composite Score] into one unpivoted pair,
and then [pediatric] and another (non existent) column in another pair.
So not only are we breaking the profile, but pediatric is also a different data type.
Does every table have those 5 columns? Does anything need to be done with those 5 columns? We will need to profile them by name and/or type or something else so that they don't break our dynamic logic.