要達成這樣很簡單
SELECT a.Custom_Fill_mID AS '序號',a.QuestName AS '報名表名稱',b.CulomnName AS '報名表欄位',CONVERT(NVARCHAR,c.DataValue) AS '欄位值' FROM
Custom_Fill_m AS a INNER JOIN
Custom_Fill_d AS b ON a.Custom_Fill_mID=b.Custom_Fill_mID INNER JOIN
Data_d AS c ON b.Custom_Fill_dID=c.Custom_Fill_dID
GROUP BY a.Custom_Fill_mID ,a.QuestName,b.CulomnName,CONVERT(NVARCHAR,c.DataValue)
UNION
SELECT a.Custom_Fill_mID,NULL,NULL,NULL FROM
Custom_Fill_m AS a INNER JOIN
Custom_Fill_d AS b ON a.Custom_Fill_mID=b.Custom_Fill_mID INNER JOIN
Data_d AS c ON b.Custom_Fill_dID=c.Custom_Fill_dID
GROUP BY a.Custom_Fill_mID ,a.QuestName,b.CulomnName,CONVERT(NVARCHAR,c.DataValue)
Custom_Fill_m AS a INNER JOIN
Custom_Fill_d AS b ON a.Custom_Fill_mID=b.Custom_Fill_mID INNER JOIN
Data_d AS c ON b.Custom_Fill_dID=c.Custom_Fill_dID
GROUP BY a.Custom_Fill_mID ,a.QuestName,b.CulomnName,CONVERT(NVARCHAR,c.DataValue)
UNION
SELECT a.Custom_Fill_mID,NULL,NULL,NULL FROM
Custom_Fill_m AS a INNER JOIN
Custom_Fill_d AS b ON a.Custom_Fill_mID=b.Custom_Fill_mID INNER JOIN
Data_d AS c ON b.Custom_Fill_dID=c.Custom_Fill_dID
GROUP BY a.Custom_Fill_mID ,a.QuestName,b.CulomnName,CONVERT(NVARCHAR,c.DataValue)
這樣就好了