使用先前制作的列

时间:2015-06-01 11:52:11

标签: sql stored-procedures

我正在创建一个存储过程,其中我已经使用AS“NameofColumn”方法声明了一个列。现在我想在稍后的存储过程中再次使用该值。反正有吗?

      CASE 
     WHEN ((select top 1 stuksweergeven from componenten where componentid = componentlink.componentid) = 1) and  ((select AmountKG from componenten where componentid = componentlink.componentid) <> 0) THEN 
        Amount * (select AmountKG from componenten where componentid = componentlink.componentid)
     ELSE 
        Amount 
  END AS Amount 

现在我想要做以下

Amount * 10 AS TotalAmount

1 个答案:

答案 0 :(得分:0)

使用子查询计算“金额”,然后从该子查询中选择。这样的事情:

select Amount * 10 AS TotalAmount from ( SELECT CASE 
         WHEN ((select top 1 stuksweergeven from componenten where componentid = componentlink.componentid) = 1) and  ((select AmountKG from componenten where componentid = componentlink.componentid) <> 0) THEN 
            Amount * (select AmountKG from componenten where componentid = componentlink.componentid)
         ELSE 
            Amount 
      END AS Amount FROM yourtable )e