Solved

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

Posted on 2007-11-14
1
13,720 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
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now