Re: Error converting a text field to a datetime datatype, who can figure this anyone????
From: Erland Sommarskog (sommar_at_algonet.se)
Date: 03/02/04
- Next message: Olivia: "Setting up Alerts to monitor DB Logs"
- Previous message: Miklos: "SQL web application fails at login. Need help."
- In reply to: Sd: "Error converting a text field to a datetime datatype, who can figure this anyone????"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 2 Mar 2004 23:17:16 +0000 (UTC)
Sd (nowhere@sadfs.com) writes:
> I have been trying to convert whatever I can but I keep getting errors
> when I perform a
>
> SELECT CONVERT(datetime, text_field) FROM Old_data
>
> Obviously my select statemt is abruptly terminated when I hit one of these
> records with a invalid date.
>
> I tried looping throught the records using a curson and try to capture and
> check for errors:
But since SQL Server thinks conversion error is reason enough for aborting
the batch, that does not fly.
But this should do:
SELECT CASE WHEN is_date(text_field) = 1
THEN convert(datetime, text_field)
END
-- Erland Sommarskog, SQL Server MVP, sommar@algonet.se Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
- Next message: Olivia: "Setting up Alerts to monitor DB Logs"
- Previous message: Miklos: "SQL web application fails at login. Need help."
- In reply to: Sd: "Error converting a text field to a datetime datatype, who can figure this anyone????"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|