Validation, presentation, calculation etc. There are few absolutes in SQL server but you should always always always store datetime data in a datetime column. Like I said, the best approach is to use datetime. Select BadDate, convert(varchar, cast(CAST(BadDate as CHAR(8)) as datetime), 101) from #BadDates This is likely to perform horribly if you have very much data because it has to be fiddled with so much. Nevertheless, your method will prove handy should I need to convert a stupiddate created by a moron to a DATE column. This allows me to join it to a fact table which has a DateKey column with that format. It will NOT convert a varchar column to anything other than the original data. Sql convert string to date yyyymmdd code#I just need to create a column with the YYYYMMDD format. Your code will convert a datetime to the display format you desire. UGH!!! Display formatting really should happen in the front end.of course that isn't always possible. The date format was fine, it is just a date column no string attached. The real ugliness is that you have to first convert your decimal to a varchar and to a datetime so that you can convert it to a display value. To work with it as is you need to make sure you that your dateformat is the same as the table is stored and that you don't have any values that are not valid datetimes values. I have been working on this for a while.all my efforts to get the right result are futile (ĮEK! Any chance you can make it a datetime? Why decimal? That's why the above code is not giving the right result. You are right mycolumn is defined as decimal in its DDL statement.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |