开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜