SQL Server Reference a Calculated Column

前端 未结 6 1077
傲寒
傲寒 2020-12-30 21:23

I have a select statement with calculated columns and I would like to use the value of one calculated column in another. Is this possible? Here is a contrived example to s

6条回答
  •  一个人的身影
    2020-12-30 21:44

    You can't "reset" the value of a calculated column in a Select clause, if that's what you're trying to do... The value of a calculated column is based on the calculated column formulae. Which CAN include the value of another calculated column.... but you canlt reset the formulae in a Select clause... if all you want to do is "output" the value based on two calculated columns, (as the syntax in your question reads" Then the "[calcval2]"
    in

    SELECT [calcval1] = CASE Statement, [calcval2] = [calcval1] * .25 
    

    would just become a column alias in the output of the Select Clause.

    or are you asking how to define the formulae for one calculated column to be based on another?

提交回复
热议问题