UPDATE each item in a column
I'm having trouble figuring out a solution to this. I have several tables in my database with attributes having a date type. However, in one of my tables I was not thinking during the design process so the attribute is not of date but is a varchar. The dates in the "incorrect" table is formatted as dd-MMM-yyyy whereas all of the other dates are formatted as yyyy-mm-dd.
How can I run through the "incorrect" column and do CAST(myDate AS date) on e开发者_StackOverflow中文版ach mis-typed attribute?
I'd migrate to a date column.
- Add a nullable
datecolumn - Run an update query to set the value of each column to the result of your cast
- Drop the
varcharcolumn - Refactor your code or rename the new column to the name of the old one
加载中,请稍侯......
精彩评论