Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSQL - efficient way of setting multiple variables

is their a more efficient way of doing this?

set @ShippingL = (select ShippingL from AuctionProducts where ProductID = @ProductID)
set @ShippingB = (select ShippingB from AuctionProducts where ProductID = @ProductID)
set @ShippingH = (select ShippingH from AuctionProducts where ProductID = @ProductID)
set @ShippingW = (select ShippingW from AuctionProducts where ProductID = @ProductID)

Cheers, -R

like image 837
Rya Avatar asked Feb 12 '11 06:02

Rya


1 Answers

I would think doing one query would be as good as you'll get it:

select 
  @ShippingL = ShippingL,
  @ShippingB = ShippingB,
  @ShippingH = ShippingH,
  @ShippingW = ShippingW 
from 
  AuctionProducts 
where
  ProductID = @ProductID 

I would imagine this is 4 times faster than the code that you posted. Also, make sure that you have an index defined on the ProductID column of the AuctionProducts table.

like image 123
sheikhjabootie Avatar answered Nov 08 '22 14:11

sheikhjabootie