sql server - SQL: Referencing calculated columns in other parts of the query -


i following in sql server 2012:

select unitprice * quantity subtotal,        subtotal * (1-0.13) tax,        tax + subtotal total invoice 

as far know, not possible written above, wondering if there special way of identifying column on fly referenced elsewhere in query such "field list" (part of select clause), part of clause or in order clause.

any appreciated.

you can calculations in cross apply.

select t1.subtotal,        t2.tax,        t2.tax + t1.subtotal total invoice   cross apply (select i.unitprice * i.quantity) t1(subtotal)   cross apply (select t1.subtotal * (1 - 0.13)) t2(tax) 

sql fiddle


Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -