2015-06-01 23 views
0

我正在创建一个存储过程,其中我声明了一个带有“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 
+0

如果您想要重新使用'SELECT'中定义的列别名,则需要使用子查询或CTE。 –

回答

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