sql将结果传递给另一个计算

时间:2016-11-18 10:44:52

标签: sql-server

当我得到

时,如何将结果传递给另一个计算
  

无效的列名称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]*2+@diameter11)*PI()) AS "omkreds for 11 tommer",
          (Select ([profilhøjde]*2+@diameter12)*PI()) AS "omkreds for 12 tommer"
        )a

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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