Set Vs Select statement in SQL Server

Using set statement, you can't set more than one value where as in select we can set more than one value. So we can achieve it in a single line of statement to assign values to multiple variables. Performance wise there will be a very very small change and it's good for select.

-- Set statement in SQL Server

declare @val int=0, @val1 int
print @val
set @val=1
-- set @val=1,@val1=2 (You can't set multiple values)
print @val

 
-- Select statement in SQL Server
declare @val int=0, @val1 int
print @val
select @val=1,@val1=2
print @val
 
Cheers,
Venkatesan Prabu .J
Ebook Download
View all
Learn
View all