如何優化這個代碼可以爲O(n)的分配值@TollPrice運行:如何優化這個SQL查詢
IF (EXISTS (SELECT TollPrice
FROM Car_TaxInfo
WHERE (car_subgrp_id = @Kind) AND (Sal = @Sal)))
BEGIN
SELECT @TollPrice = TollPrice
FROM Car_TaxInfo
WHERE (car_subgrp_id = @Kind) AND (Sal = @Sal)
SET @IsExistToll = 1
END
ELSE
BEGIN
SET @IsExistToll = 0
END
刪除if存在,只需選擇該值並在其後面檢查@@ rowcount。另外,檢查是否有正確的索引 –
@JamesZ謝謝;) –