SQL Server Compute Scalar Operator – Part1

Dear Friends,

SQL Server compute scalar operator performs a scalar computation and returns computed value. This calculation can be as simple as conversion of value or could be concatenation of value. Most of the times, this operator represents minimal cost as compared to the execution plan and hence overlooked. It is recommended to have a proper look when we are dealing with complex loops, cursors and if we are experiencing CPU bottlenecks.

Let us take a look into this operator using simple query statement.

USE [AdventureWorks2012]

DECLARE @Table TABLE(ID SmallInt PRIMARY KEY)

SELECT 'SQLServerGeeks' + '.' + 'Com' FROM @Table

CSQueryPlan

CSToolTip

To understand Expr1003, let us decode query plan in text.

USE [AdventureWorks2012]

--Step1
SET SHOWPLAN_TEXT ON

--Step2
DECLARE @Table TABLE(ID SmallInt PRIMARY KEY)

SELECT 'SQLServerGeeks' + '.' + 'Com' FROM @Table

--Step3
SET SHOWPLAN_TEXT OFF

CSQueryPlanText

The plan generated using compute scalar simply did the concatenation between ‘SQLServerGeeks’, ‘.’  and ‘com’. We are going to discuss more on this operator tomorrow, stay tuned.

Happy learning!

Regards,

Kanchan

Like us on FaceBookJoin the fastest growing SQL Server group on FaceBookFollow me on TwitterFollow me on FaceBook

Avatar

About Kanchan Bhattacharyya

Kanchan is an astute IT professional, a seasoned SQL Database Administrator with 13+ years of industry experience. A calculated risk taker with deep technical knowledge and has gained proficiency in database consulting and solutions across different environments. Kanchan holds MBA degree in IT and an International Executive MBA in Project Management. He is very passionate about SQL Server and holds MCSE (Data Platform), MCSA – SQL 2012, MCITP – SQL 2008 certifications. Currently he is focusing on cloud and latest releases of SQL Server. When not working, Kanchan likes to spend his time reading on new technical developments specifically on SQL Server and other related technologies.

View all posts by Kanchan Bhattacharyya →

Leave a Reply

Your email address will not be published. Required fields are marked *