Home Forums Data Warehousing Integration Services how to check whether in the given column we have values in date format RE: how to check whether in the given column we have values in date format

  • there is an ISDATE function in SQL as well;

    here's an example base don your post:

    /*

    /*

    Eid Variable Date? Converted?

    ---- --------- ----------- -----------------------

    1 na 0 NULL

    2 none 0 NULL

    3 4/18/2013 1 2013-04-18 00:00:00.000

    4 18/2013 0 NULL

    5 2013 1 2013-01-01 00:00:00.000

    6 9999999 0 NULL

    */

    WITH MySampleData (Eid,Variable)

    AS

    (

    SELECT '1','na' UNION ALL

    SELECT '2','none' UNION ALL

    SELECT '3','4/18/2013' UNION ALL

    SELECT '4','18/2013' UNION ALL

    SELECT '5','2013' UNION ALL

    SELECT '6','9999999'

    )

    SELECT

    MySampleData.*,

    ISDATE(Variable) AS [Date?],

    CASE

    WHEN ISDATE(Variable) = 1

    THEN CONVERT(datetime,Variable)

    ELSE NULL

    END As [Converted?]

    FROM MySampleData

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!