0
我想弄清楚如何在SQL Server 2008 R2中的表格進行格式化/分組。我已經絞盡腦汁想到如何做到這一點,但無法想出辦法。下面是表T-SQL構建出一個組的列由
Pkey Account_No Contact_Date Flag Job
1 10001 2013-12-09 y apple
2 10001 2013-12-10 n orange
3 10002 2013-12-02 n apple
4 10003 2013-12-10 y pear
5 10003 2013-12-11 n peach
6 10003 2013-12-12 n apple
本質上講,我需要有作爲輸出的基本佈局在某種程度上組由account_no上(僅適用於不同account_no上的上市),但後來從他們建了contact_dates和標誌的命令日期。理論上建立的列可以永遠消失。請參閱下面的表格作爲輸出示例:
Account_No Contact_Date_1 Flag_1 Job_1 Contact_Date_2 Flag_2 Job_2 Contact_Date_3 Flag_3 Job_3
10001 2013-12-09 y apple 2013-12-10 n orange NULL NULL NULL
10002 2013-12-02 n apple NULL NULL NULL NULL NULL NULL
10003 2013-12-10 y pear 2013-12-11 n peach 2013-12-12 n apple
感謝您提前提供任何幫助!
你想要那個輸出嗎? –
如果account_no有5個contact_date值,您需要5組列,並且如果account_no有26個contact_date值,那麼您需要26組列? Yikes(沒有雙關語意)。將此透視留給表示層。 –