[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.
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
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?
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?