2016-11-18 22 views
0

我如何通過我的結果到另一個計算,因爲我得到一個SQL傳遞結果到另一個測算

無效的列名profilhøjde

什麼是做這種正確的方法是什麼?

  select * from 
     (select ([brede]*[Profil])/100 as "profilhøjde" 
     from [Tabel].[dæk] 
     )a 

     select * from 
     (select ("profilhøjde" *2 + @diameter10)*PI() as "omkreds for 10 tommer", 
      (Select ([profilhøjde]*[email protected])*PI()) AS "omkreds for 11 tommer", 
      (Select ([profilhøjde]*[email protected])*PI()) AS "omkreds for 12 tommer" 
     )a 

回答

1
declare @diameter10 int 

    select ("profilhøjde" *2 + @diameter10)*PI() as "diameter 10 tommer" 
,("profilhøjde" *2 + @diameter10)*PI() as "diameter 10 tommer" 
, ("profilhøjde" *2 + @diameter11)*PI() as "diameter 11 tommer" 
, ("profilhøjde" *2 + @diameter10)*PI() as "diameter 12 tommer" 
from 
     (select ([brede]*[Profil])/100 as "profilhøjde" 
     from [Tabel].[dæk] 
     )a 
+0

是否有可能不顯示直徑的結果sometinhg類似於'SET' –

+0

對不起,我沒有得到你在說什麼.. @ ominidata解釋清楚 – Chanukya

+0

abit像當我使用'SET @ tommer10 = 10 SET @ diameter10 = @ tommer10 * 25.4 ',而不是選擇,所以我不看到thoose –

1

使用CTE

Here More On CTE

;with a as 
(
select ([brede]*[Profil])/100 as "profilhøjde" 
from [Tabel].[dæk] 
) 

    select ("profilhøjde" *2 + @diameter10)*PI() as "diameter 10 tommer" 
,("profilhøjde" *2 + @diameter10)*PI() as "diameter 10 tommer" 
, ("profilhøjde" *2 + @diameter11)*PI() as "diameter 11 tommer" 
, ("profilhøjde" *2 + @diameter10)*PI() as "diameter 12 tommer" 
from a 
+0

如果我想有從一個倍數計算像 '選擇( 「profilhøjde」 * 2 + @ diameter10) * PI()as「diameter 10 tommer」 select(「profilhøjde」* 2 + @ diameter11)* PI()as「diameter 11 tommer」 select(「profilh JDE」 * 2 + @ diameter10)* PI()爲 「從A' –

+0

它將工作並且還直徑12 tommer」 子查詢也會工作.. @ ominidata – Chanukya

+0

@ominidata Editted答案。 –

相關問題