If @DateMin < @DateMax
Begin
(Select InvoiceNumber, InvoiceDate, InvoiceTotal, InvoiceTotal-PaymentTotal-CreditTotal AS Balance
That bracket right after the begin that shouldn't be there.
InvoiceDate < @DateMax+1
Meaning 1 day later than the datemax that the user specified?
You shouldn't name procs sp_. That's for system stored procs and means that SQL will look first in one of the system databases to see if your proc is there
What should happen if Datemin = DateMax? Currently the proc will do nothing if that happens.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability