Solved

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

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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

746 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

12 Experts available now in Live!

Get 1:1 Help Now