Solved

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

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

680 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