Friday 15 May 2015

sql server - In T-SQL, can an expression be re-used in a query without re-calculating the expression? -



sql server - In T-SQL, can an expression be re-used in a query without re-calculating the expression? -

for example, want this:

select (a , (b or c)) expressionone, not (a , (b or c)) notexpressionone sometable

where a, b, , c can expression.

is there mechanism in sql server without calculating (a , (b or c)) multiple times each row of select?

the question sql server re-calculate or not? notes value re-calculated, , gives 1 possible solution (a sub-query), doesn't mention if possible solution.

i think mutual table look (cte) this:

with (expression (one, othercolumns) (select (a , (b or c)), othercolumns sometable) select one, not one, othercolumns look

but isn't @ clear more efficient sqlserver's optimizations -- different calculations on same columns, i'd expect pretty efficient already. in particular, cte has save result of calculation somewhere, either in memory or on disk if it's big. pays seek out , see whether it's faster calculation twice or create in-memory construction calculate once.

sql sql-server performance tsql

No comments:

Post a Comment