0
有人可以解釋爲什麼在https://msdn.microsoft.com/en-us/library/ms182717.aspx的例子爲什麼在IF子句中有一個BEGIN和END,而不是ELSE子句?
DECLARE @compareprice money, @cost money
EXECUTE Production.uspGetList '%Bikes%', 700,
@compareprice OUT,
@cost OUTPUT
IF @cost <= @compareprice
BEGIN
PRINT 'These products can be purchased for less than
$'+RTRIM(CAST(@compareprice AS varchar(20)))+'.'
END
ELSE
PRINT 'The prices for all products in this category exceed
$'+ RTRIM(CAST(@compareprice AS varchar(20)))+'.'
有一個BEGIN
和END
封閉IF
塊,但不是ELSE
塊?
https://technet.microsoft.com/en-us/library/aa258853(v=sql.80).aspx和https://technet.microsoft.com /en-us/library/ms182587(v=sql.110).aspx –
@RahulTripathi你發佈的這個例子在'IF'和'ELSE'塊周圍都有'BEGIN'和'END'。所以這並不能幫助我理解我的問題。 – user5648283
我不認爲它有一個特定的原因。它只是。你可以在'IF'子句中自由移除'BEGIN ... END',或者你可以在'ELSE'中添加它們而不改變代碼的含義。 –