Home Forums SQL Server 2008 T-SQL (SS2K8) Using CAST or CONVERT to change data from string to datetime RE: Using CAST or CONVERT to change data from string to datetime

  • The script you posted should work assuming the values are within acceptable values for each datepart. As much as I hate to say this I think you may have to use a while loop here and convert these one at a time to find the culprit then. Stick all the parsed values into a temp table with an identity and an extra datetime column(with all NULL). Then you can use a while loop to go through the temp table rbar and update the current row's datetime column with your parsing logic. You will find the invalid data in there somewhere.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/