TSQL - 设置多个变量的有效方法

时间:2011-02-12 06:23:31

标签: performance tsql

他们是一种更有效的方法吗?

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)

干杯, -R

1 个答案:

答案 0 :(得分:20)

我认为做一个查询就像你得到它一样好:

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

我认为这比您发布的代码快4倍。此外,请确保在AuctionProducts表的ProductID列上定义了索引。