Returning Complicated Computed Column from a SP

  • I need to return a computed column from a stored procedure, and I will need to use this computation in other places in the same Select statement.

    A simple example might be:

    Select (Length * Width) AS 'Area',
           (Area * Height) AS 'Volume'
    From   Stuff
    Where  Area > 25

    In this case, I want to replace "Area" with the (Length * Width) formula, and use it multiple times. 

    Thank you,

      Bryan

  • You are better off using a function. Read up on 'create function' in BOL.

  • Or you could use a derived table:

    Select Area, (Area * Height) as 'Volume'

    from

    (

      select Height, (Length * Width) AS 'Area' From Stuff

    )

    as AreaStuff

    where Area > 25

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply