|
-
Nov 14th, 2006, 01:34 AM
#1
Thread Starter
Hyperactive Member
[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.
-
Nov 14th, 2006, 02:00 AM
#2
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
-
Nov 14th, 2006, 02:07 AM
#3
Thread Starter
Hyperactive Member
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?
-
Nov 14th, 2006, 02:45 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|