Results 1 to 4 of 4

Thread: [RESOLVED] date comparison [urgent]

  1. #1

    Thread Starter
    Hyperactive Member babyekc's Avatar
    Join Date
    Jul 2004
    Location
    planet earth
    Posts
    270

    Resolved [RESOLVED] date comparison [urgent]

    i have a view and a procedure. example as following:

    --View name : GET_ALL_VIEW
    SELECT employee_code,
    employee_name,
    CONVERT(VARCHAR(10), date_joined, 103) AS date_joined,
    FROM table_employee

    --Procedure name : GET_SPECIFIC_EMPLOYEE_SP
    --Parameter fields : @DateFrom DATETIME, @DateTo DATETIME
    SELECT *
    FROM GET_ALL_VIEW
    WHERE date_joined => @DateFrom
    AND date_joined =< @DateTo

    I cant get the records i wan, pls help.
    *wink wink*

    _babyekc

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: date comparison [urgent]

    The View converts the date field to a string in dd/mm/yyyy format (what is the reason for the conversion?). The sproc uses a datetime variable to compare with the string field. SQL Server then converts the string back into a datetime value for the comparison but assumes mm/dd/yyyy, resulting in out of range errors.

    Do you want to change the View or Stored Procedure? If View, remove the conversion. If sproc, convert the string field to a datetime field

    SELECT *
    FROM GET_ALL_VIEW
    WHERE Convert(datetime, date_joined, 103) >= @DateFrom
    AND Convert(datetime, date_joined, 103) <= @DateTo

  3. #3

    Thread Starter
    Hyperactive Member babyekc's Avatar
    Join Date
    Jul 2004
    Location
    planet earth
    Posts
    270

    Re: date comparison [urgent]

    the reason i convert to string is because i don wan the time. and i've tried ur solutions before i post this more than thousand times and it cant work. any another way?
    *wink wink*

    _babyekc

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: date comparison [urgent]

    What can I say? The query I posted works for me no problems.

    Are you getting an error or incorrect results?

Posting Permissions

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



Click Here to Expand Forum to Full Width