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

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -