Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-06-30 : 07:15:57
|
| Drea writes "Hi!I am new to sql server so I apologize in advance if this is a simple question -- I have imported a text file into a temp table -- the date/time fields come in 3 seperate columns -- (day (day of the month), time(time the report was run(ie 0053 for 12:53 AM) and month_year(ie 1/2000)My question is how do I get these values to read like a normal date in non temp table -- so in other words I want to take the three columns (day, time and month_year) from the temp import table and insert them into a non temp table in a recognizable date format.Any help you can give to me would be GREATLY appreciated -- I'm pulling my hair out over this one!!! : )thanks!!!" |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2004-06-30 : 07:31:53
|
| HiAssuming all the columns in your temp table are character datatypes, this should do the trick:SET DATEFORMAT DMYSELECT CONVERT(DATETIME, [day] + '/' + [month_year] + ' ' + LEFT([time], 2) + ':' + RIGHT([time], 2) + ':00')FROM #temp_tableThere's no error handling there, so if any of the information in the temp table is spurious (i.e. 13/2000 in month_year) an error will occur.Let me know how you get on.Mark |
 |
|
|
|
|
|