question

rajbhatt082 avatar image
rajbhatt082 asked

How do I ascertain the efficiency of the below code?

I have the below two expressiong in SQL Server. I wanted to understand which one is more efficient. ANy test I can run to understand which one would be more efficient.

Option A :
SET @StartingPoint = CONVERT(VARCHAR(30),CONVERT(VARCHAR,@QuestionID) + '#' + CONVERT(VARCHAR,@CurrentAnswerOption))

Option B:

SET @StartingPoint = CONCAT(@QuestionID, '#', @CurrentAnswerOption)

sql server 2012
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Jon Crawford avatar image
Jon Crawford answered

1 - why do you have to convert the result of the CONVERT () + '#'+convert() in Option A? That is already a string, seems a waste.

2 - run it with actual execution plan on and see what's what.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.