我正在尝试添加一种约束,以防止用户将来输入日期,当用户尝试这样做时,我需要它来引发错误。
这是我到目前为止所拥有的:
Create Procedure CustomerBooks (@month int, @year int)
AS
BEGIN
SELECT
SaleNumber,
month(saledate) as SaleMonth, year(saledate) as SaleYear,
CustomerNumber, EmployeeNumber, SubTotal, GST, Total
FROM
sale
Where
month(saledate) = @month
and YEAR (saledate) = @year
End
If salemonth > GETDATE(Month(saledate))
or saleyear > GETDATE(YEAR(saledate))
begin
Raiserror ('Invalid entry, you cannot enter future dates',16,1)
end
EXEC dbo.CustomerBooks @month = '1', @year = '2012'