0
我有一個接受5個參數的過程,它需要將描述設置爲一個空字符串,將dateadded設置爲currentdate(我使用GETDATE)。但我似乎無法工作的是我需要列表價格和折扣百分比在嘗試輸入負數時拋出錯誤。我的代碼有效,但是當我嘗試輸入一個負數時,我的表述不會出現錯誤。SQL不接受負數proc
USE MyGuitarShop;
GO
IF OBJECT_ID('spInsertProduct') IS NOT NULL
DROP PROC spInsertProduct;
GO
CREATE PROC spInsertProduct
@insCatID int = 0,
@insProdCode varchar(10) = 0,
@insProdName varchar(50) = 0,
@insListPrice money = 0,
@insDisPercent money = 0
AS
IF @insListPrice < 0
PRINT 'this column does not accept negative numbers';
IF @insDisPercent < 0
PRINT 'this column does not accept negative numbers';
UPDATE Products
SET Description = '', DateAdded = GETDATE();
SELECT CategoryID, ProductCode, ProductName, ListPrice, DiscountPercent
FROM Products
USE MyGuitarShop;
GO
EXEC spInsertProduct
-7,'254-652','Guitar', -300.01, 30.00;