I want to return 3 single values from 3 different tables.
I want to know which of these codes are better considering resource usage and performance (in a stored procedure):
Code 1:
declare @acc_cnt int, @selected_item int, @worker_cnt int
select @acc_cnt=count(0) from accounts
select @selected_item=id from items where name='something'
select @worker_cnt=count(0) from workers
select @acc_cnt ,@selected_item,@worker_cnt
Code 2:
select count(0) from accounts
select id from items where name='something'
select count(0) from workers
Is there a difference between returning 3 selects and a single select? I’m using SQL Server 2008
Number 2 would be SLIGHTLY a performance improvement, as you are not declaring the variables and saving a small amount of memory.
Note: The performance improvement would be almost immeasurable.