We help IT Professionals succeed at work.

SQL variable restriction

246 Views
Last Modified: 2014-08-25
I'm creating a stored proc with a variable @AsOfDate as date. Now, I only want to accept the input date if it is within 3 days of today, otherwise it should not accept it and throw an error. Currently I'm doing this with a IF/ELSE statement. Is there a better way of handling this?

I'm using SQL 2012
Comment
Watch Question

SQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
So that's exactly how I'm doing it right now. I assume this is the correct and most efficient way of handling it?
Jim HornSQL Server Data Dude
CERTIFIED EXPERT
Most Valuable Expert 2013
Author of the Year 2015

Commented:
I'm sure there are other ways, but this is the way I'd do it.

btw Did you really want to throw an error, which would involve RAISEERROR, or just handle it?

Author

Commented:
If this stored proc is run from Excel VBA, I want the user to see the error message I give.
Vitor Montalv√£oIT Engineer
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.