Home Forums SQL Server 2008 SQL Server 2008 - General Help with doing “Cast the decimal as string, parse into the format specified, and then cast back into datetime”? RE: Help with doing “Cast the decimal as string, parse into the format specified, and then cast back into datetime”?

  • based on the other thread for the same issue the problem is SOME of his data is YYYYMMDD as a decimal, like 20121225, but some of his data is not in the same format, and as a result, he gets an error converting the STR({somedecimal}) to a datetime.

    i think the key there is to look at the values that are not convertable to datetime;

    something like SELECT * From MyTable Where LEN(STR(MyDateField)) <> 8 for starters.

    beating the dead horse one more time, the fix is to use datetime columns for datetime values. it would be best to take the time to fix this issue...and it's probably not just this one column that is suffering from the issue...you might create a work around for this one column, only to have it show up again tomorrow on a different table or column.

    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!