Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Out Of Range Date Type

Status
Not open for further replies.

mentasses

Technical User
Mar 23, 2004
29
GB
I have a simple update query:

UPDATE SERVICES.dbo.MASTER
SET DATEOFLEAVING = CONVERT(Char,b.DATELEAVE,103)
FROM SERVICES.dbo.MASTER a JOIN SERVICES.dbo.EXITINTERVIEW b
ON a.STAFFNO = b.STAFFNO

When I run the query I receive the error message:

Server: Msg 242, Level 16, State 3, Line 1
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.

Can anyone help?
 
The datatype should be date format but I think some data has been entered as text.
I do not know how to ensure the datatype is correct before running the update?

 
Got a little bit confused... if dateofleaving is of type date, they why CONVERT(char... )?
 
I need the date as DD/MM/YYYY
Although if I just use
SET DATEOFLEAVING = DATELEAVE
I still get the same error message
 
Argh... then DATEOFLEAVING is date and DATELEAVE char/varchar, right?

If true, then some of DATELEAVE values may be out of range (year below 1753) or invalid (Feb 30th or something). To check that, use ISDATE() function. Also: you can use SET DATEFORMAT dmy before UPDATE statement but this is maybe not necessary.
 
It appears that both DATELEAVE and DATEOFLEAVING have some date and some varchar data.
Is their a way I can convert them all to date format before I run the update?
 
DATELEAVE and DATEOFLEAVING need to be a defined data type in the table - each of them have there own type - which one is datetime and which one is varchar/char.



[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Run a query on the column using ISDATE.

For example:

Code:
SELECT ISDATE(DATELEAVE)
FROM ExitInterview

Refer to the BOL for more information on ISDATE.

-SQLBill

BOL=Books OnLine=Microsoft SQL Server's HELP
Installed as part of the Client Tools
Found at Start>Programs>Microsoft SQL Server>Books OnLine

Posting advice: FAQ481-4875
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top