How to set Proc Arg to default to today?

  • Hi folks,

    trying to set the default and date to today ... I know that I must be mising something stupid ... here is what I have:

    
    
    CREATE PROCEDURE rptCurrentInCome
    @RunnerID INT=NULL,
    @StartDate DATETIME='01/01/1900',
    @EndDate DATETIME=GETDATE()
    AS ...

    Edited by - robby_disco on 04/10/2003 10:19:13 AM

  • Default parameters must be NULL or a Constant. GETDATE is obviously not a constant.

    Try:-

    alter PROCEDURE rptCurrentInCome

    @RunnerID INT=NULL,

    @StartDate DATETIME='01/01/1900',@EndDate DATETIME=NULL

    AS

    if @enddate is null set @enddate = GETDATE()

    ...

  • According to BOL: "The CREATE PROCEDURE statement cannot be combined with other Transact-SQL statements in a single batch."

    So I guess you can't combine GETDATE() with CREATE PROC. May be you can just do ... err... wait, ianscarlett already answered what I wanted to say. 😛

  • Robby,

    Yeah... looks like T-SQL doesn't like function calls in proc declarations. I didn't know that. You could set the date to GetDate() after the parameter declarations:

     
    
    CREATE PROCEDURE rptCurrentInCome
    @RunnerID INT=NULL,
    @StartDate DATETIME='01/01/1900',
    @EndDate DATETIME=NULL
    AS
    SET @EndDate = GetDate()
    .
    .
    .

    HTH,

    SJTerrill

  • Thanks for the help folks ...

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply