sql stored procedure

I need to create a stored procedure named spDateRange that accepts two parameters, @DateMin and @DateMax, with data type varchar and default value null. If called with no parameters or with null values, the procedure should return an error message describing the syntax. If called with non-null values, validate the parameters. Test that the literal strings are valid dates and test that @DateMin is earlier than @DateMax. If the parameters are valid, return a result set that includes the InvoiceNumber, InvoiceDate, InvoiceTotal, and Balance for each invoice for which the InvoiceDate is within the date range, sorted with earliest invoice first.

I ma having problem with the message to show the error while checking the syntaxt , I can not get prcedure to read the insturction another words multi statement table to return instructions.
tagtekinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Anthony PerkinsCommented:
CREATE Procedure spDateRange
            @DateMin varchar(20) = Null,
            @DateMax varchar(20) = Null

As

SET NOCOUNT ON

Declare @Error tinyint

If @DateMin Is Null Or @DateMax Is Null
      Return 1

If ISDATE(@DateMin) = 0 Or ISDATE(@DateMax) = 0
      Return 2

If CAST(@DateMin as datetime) >= CAST(@DateMax as datetime)
      Return 3


Select      InvoiceNumber,
      InvoiceDate,
      InvoiceTotal,
      Balance
From      Invoices
Where      InvoiceDate BETWEEN CAST(@DateMin as datetime) AND CAST(@DateMax as datetime)
Order By InvoiceDate

Return 0
0
Anthony PerkinsCommented:
Let's try that again (I left a testing line)

CREATE Procedure spDateRange
            @DateMin varchar(20) = Null,
            @DateMax varchar(20) = Null

As

SET NOCOUNT ON

If @DateMin Is Null Or @DateMax Is Null
      Return 1

If ISDATE(@DateMin) = 0 Or ISDATE(@DateMax) = 0
      Return 2

If CAST(@DateMin as datetime) >= CAST(@DateMax as datetime)
      Return 3

Select      InvoiceNumber,
      InvoiceDate,
      InvoiceTotal,
      Balance
From      Invoices
Where      InvoiceDate BETWEEN CAST(@DateMin as datetime) AND CAST(@DateMax as datetime)
Order By InvoiceDate

Return 0
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tagtekinAuthor Commented:
thanks thats works
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.