Using features like the mentioned spencer7593 is the right approach for dynamic data. For static data, a more efficient approach compatible with the design of SQL data (compared to the anti-template of massive procedural code in sprocs) is to create a separate table with static values โโand join it. This is extremely beneficial from a perspective perspective, as SQL Engine can create efficient execution plans around JOINs, and you also have the option of adding indexes if necessary.
The disadvantage of using functions (or any built-in calculated values) is that shutdown occurs for each returned potential row, which is expensive. What for? Because SQL must first create a complete dataset with calculated values, and then apply the WHERE clause to that dataset.
Nine times out of ten you do not need dynamically calculated cell values โโin your queries. It is much better to understand what you need, and then create a data model that supports it, and fill this data model with semi-dynamic data (for example, using batch jobs) and use the SQL Engine to do the heavy work using standard SQL.
Shane Sep 01 '16 at 2:07 a.m. 2016-09-01 14:07
source share