Catch SQL Cast ERROR

Posted on 2007-10-03
Last Modified: 2012-05-05
I need to find all instances where a field cannot be cast to date time.  How can I select all fields that fail the cast?
Question by:Rowdyone52
    LVL 92

    Accepted Solution

    SELECT (CASE WHEN ISDATE(SomeColumn) = 1 THEN CAST(SomeColumn AS datetime) ELSE NULL END) AS foo
    FROM SomeTable
    LVL 65

    Expert Comment

    by:Jim Horn
    SELECT YourColumnNameGoesHere
    FROM YourTableNameGoesHere
    WHERE ISDATE(YourColumnNameGoesHere) = 0

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
    JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now