支援公文專案時,遇見要將明細檔 根據Type 不同 ,將內容組合起來的問題 之後再列轉行。
當下其實發現有點難做,後來想到以前許久支援SWS 報表問題,發現可以運用它 直接解決
這次在特別紀錄一下。
直接先用db資料描述問題
1.以下是DB 測試資料
2.想要的結果 類似如下
以下解法:
首先先利用FOR XML PATH 將資料先串再一起
順便將Type命名 方便之後列轉行直接使用行名稱
接著使用PIVOT 進行列轉行
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.
評論