Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-14
1
Medium Priority
?
13,760 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 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

Ready to get certified? Check out some courses that help you prepare for third-party exams.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

927 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