源视图:
使用 Pivot 行转列进行处理;
语句如下:
select m.*,a.A as AccountA,a.B as AccountB,a.C as AccountC,a.D as AccountD,a.E as AccountE,a.F as AccountF,a.G as AccountG from
(select TypeCode,Account,MainCode from Sale_AdvanceType) p
pivot
(
max(Account)
for
TypeCode in ([A],[B],[C],[D],[E],[F],[G])
)a left join Sale_AdvanceMain m on a.MainCode=m.SMainCode
结果视图: