我有一个选择一些数据的查询,我在其中传递了一些参数:
DECLARE @FromAccDocNo INT = 1,
@ToAccDocNo INT = 999999999,
@FromDate CHAR(10) = '1900/01/01',
@ToDate CHAR(10) = '2999/12/30',
@L1Code INT = 129
SELECT ad.AccDocNo,
ad.AccDocDate,
add1.Row,
add1.RowComment,
add1.Debit,
add1.Credit
FROM AccDoc ad
INNER JOIN AccDocDetail add1
ON add1.AccDocNo = ad.AccDocNo
INNER JOIN Topic t
ON t.TopicCode = add1.TopicCode
WHERE t.L1Code = @L1Code -- here is the difference
AND add1.AccDocNo BETWEEN @FromAccDocNo AND @ToAccDocNo
AND ad.EffectiveDate BETWEEN @FromDate AND @ToDate
ORDER BY
ad.AccDocNo
首先,我将值 129 明确写为@L1Code
(需要 0.010 秒)
在第二种形式中,我@L1Code
进入查询(需要 2.500 秒)
谁能解释会发生什么?