I made some modifications to the code but cont to get an error message when creating the procedure. Here is the latest code and my error.
CREATE PROCsp_DateRange
@DateMin DateTime = NULL,
@DateMax DateTime = NULL
AS
If (@DateMin is null)
begin
Raiserror('Please enter the MinimumDate ',16,1)
Return
End
If (@DateMax is null)
begin
Raiserror('Please enter the MaximumDate ',16,1)
Return
End
If (@DateMin > @DateMax)
begin
Raiserror('Minimum Date can’t be later then maximum date ',16,1)
Return
End
If @DateMin < @DateMax
Begin
(Select InvoiceNumber, InvoiceDate, InvoiceTotal, InvoiceTotal-PaymentTotal-CreditTotal AS Balance
From Invoices
Where InvoiceDate >= @DateMin and InvoiceDate < @DateMax+1
Order By InvoiceDate
END
--Error Message
Incorrect syntax near the keyword 'Order'.