Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002
    Posts
    192

    Unanswered: Passing in Date Parameters

    I have a stored procedure that accepts a date value.

    Create Procedure spTest as
    @DateFrom DateTime,
    @DateTo DateTime
    /* Procedure Logic Not Shown */
    GO


    I'm trying to pass in a date generated from Functions.

    EXECUTE spTest Month(GetDate()) + '/1/2003', '2/2/2003'

    When I run the Stored Procedure I get an "error near Month" but when I hard code in a date things work fine. i.e. '1/1/2003'. Any ideas?

  2. #2
    Join Date
    Mar 2003
    Location
    Bucharest, Romania
    Posts
    80

    Re: Passing in Date Parameters

    From the code taht you presented to us, I see two problems:

    1)
    Create Procedure spTest as
    @DateFrom DateTime,
    @DateTo DateTime
    /* Procedure Logic Not Shown */
    GO

    should be like this:
    Create Procedure spTest @DateFrom DateTime,
    @DateTo DateTime as
    /* Procedure Logic Not Shown */
    GO

    but this one I think it's just a type error when you posted your question, because you said that the sp worked when you passed the parameters hardcoded. The sp would never work (and never compile) in the form mentioned in your post

    2)
    Instead of:
    EXECUTE spTest Month(GetDate()) + '/1/2003', '2/2/2003'
    I would use:
    EXECUTE spTest '' & Month(GetDate()) & '/1/2003', '2/2/2003'

    Good luck!
    ionut calin

  3. #3
    Join Date
    Mar 2002
    Posts
    192
    EXECUTE spTest '' & Month(GetDate()) & '/1/2003', '2/2/2003'

    I paired up the quotes and the above line doesn't seem to work. Also tried:

    EXECUTE spTest '' & Month(GetDate()) & '/1/2003''', '2/2/2003'
    EXECUTE spTest Month(GetDate()) & '/1/2003', '2/2/2003'
    EXECUTE spTest Month(GetDate()) + '/1/2003', '2/2/2003'

    Just in case it was a data conversion issue I tried the following as well.

    EXECUTE spTest CONVERT(VARCHAR(2), Month(GetDate)) + '/1/2003', '9/1/2003'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •