Using alias in equations

  • Guys,

    I know this query works with Sybase, but it does not work with sql server,

    select

    (quantity * price) as subtotal,

    (subtotal * .05) as tax

    from

    table

    Does anybody know any solution to this?

    (without changing the second "subtotal" to "quantity * price")

  • select subtotal, (subtotal * .05) as tax

    FROM (select (quantity * price) as subtotal

              from table) DT

    _____________
    Code for TallyGenerator

  • Use a derived table:

    SELECT   subtotal

          , (subtotal * 0.5) as tax

    FROM  (select

                 (quantity * price) as subtotal

           from table) t

     

    Scott Thornburg

  • Oh so you use a derived table!! Thanks guys.

    You guys posted at the same time

  • Fools think same way.

    _____________
    Code for TallyGenerator

Viewing 5 posts - 1 through 4 (of 4 total)

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