2016-03-23 43 views
-3

我想創建下面的語句的看法:創建一個視圖,其中包括高管

declare @tab1 varchar(20); 

declare @tab2 varchar(20); 

declare @tab3 varchar(20); 

select @tab1 = tablet from result where RANK = 1; 

select @tab2 = tablet from result where RANK = 2; 

select @tab3 = tablet from result where RANK = 3; 


exec(' 
SELECT [1] AS '[email protected]+', [2] AS '[email protected]+', [3] AS '[email protected]+' 
FROM (SELECT RANK, time, row_number() OVER (partition BY koy 
ORDER BY time ASC) AS ranking 
FROM result) s 
PIVOT (max(time) FOR rank IN ([1], [2], [3])) p'); 
+0

什麼似乎是這個問題?你不誠實地期待我們猜測..? – sagi

+2

可能重複的[在SQL中動態更改列名稱](http://stackoverflow.com/questions/16185425/change-columns-name-dynamically-in-sql) – Lucero

+0

請谷歌和了解有關CREATE VIEW語句及其限制。 –

回答

2

不能創建具有動態列名的視圖,它的定義必須是靜態的。

不幸的是,你想要做的甚至不可能(允許)在一個表值多態函數中,因爲它們也不允許動態SQL執行。

相關問題