Solved

SQL Server Stored Procedure default datetime parameter to today minus 30 days

Posted on 2007-11-14
1
13,736 Views
Last Modified: 2010-08-05
I want to create a stored procedure in SQL server 2000 with a parameter that will default to today's date minue 30 days. I would also like to ability to over ride the default value in the stored procedure call if I need to.This is what I have. it is giving me an error.

CREATE PROCEDURE OH_Head
@start_date datetime = dateadd(day,-30,getdate())

AS

GO
0
Comment
Question by:estanton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 6

Accepted Solution

by:
Marcel Hopman earned 500 total points
ID: 20284400
An parameter can only have constant default values... you could rewrite it with a little overhead:

CREATE PROCEDURE OH_Head
@start_date datetime = NULL
AS
IF @start_date IS NULL
   SET @start_date = dateadd(day,-30,getdate())

GO
0

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question