开发者

ASP & SQL Server 2008 : calculated value from another calculated value

开发者 https://www.devze.com 2023-04-01 17:44 出处:网络
I need to use a SQL statement that is bound to a Gridview & needs to be something like SELECT * from Table Sum(Column1) AS S00, (S00/CONSTANT) AS C01 or

I need to use a SQL statement that is bound to a Gridview & needs to be something like

SELECT * from Table Sum(Column1) AS S00, (S00/CONSTANT) AS C01 or

SEL开发者_开发知识库ECT * from Table Sum(Column1) AS S00, Sum(Column1) / CONSTANT AS C01

CONSTANT will be a value passed to the query as a session variable.

i.e the 2nd column of the Gridview is calculated from the result of 1st calculation.

What will be the best way to achieve this?


You'll need to repeat the expression, or use a subquery e.g.

SELECT *, C01 = (S00/Constant) 
FROM
(
 SELECT S00 = SUM(Column1)
  FROM table
) AS x;
0

精彩评论

暂无评论...
验证码 换一张
取 消