What is the better way (with regards to performance) to set a value to variable?
-
By
SET
command:DECLARE @VarString nvarchar(max); SET @VarString = 'john doe'; SELECT @VarString;
-
By
SELECT
command:DECLARE @VarString nvarchar(max); SELECT @VarString = 'john doe'; SELECT @VarString;
Best Answer
Don't pick one or the other strictly for performance.
Pick based on what fits your style and development needs, as is advised in the conclusion to this excellent comparison between
SELECT
andSET
(emphasis and minor formatting added):