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 |
|
scelamko
Constraint Violating Yak Guru
309 Posts |
Posted - 2005-04-13 : 09:00:36
|
| Guys, I have scenario dealing with datetime fieldsThere are 2 columns date and time which are both varchar(50) fields Date has data in the format 04/13/2005 Time has data in the format 11:34I have created new column named date_time with datetime datatypeNow I want to update this column with concatenation of date and time fields but it errors out for me.However, it works when I try to update date_time column with date only.Any workarounds for this scenario would help Thanks |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-04-13 : 09:44:19
|
| [code]USE NorthwindGOSET NOCOUNT ONCREATE TABLE myTable99([date] varchar(50), [time] varchar(50), [datetime] datetime)GOINSERT INTO myTable99([date],[time])SELECT '04/13/2005','11:34' UNION ALL SELECT '04/13/2005','25:00' UNION ALL SELECT '04/33/2005','11:34' UNION ALL SELECT 'Brett','Kaiser'GO-- Show all Bad datetime valuesSELECT * FROM myTable99 WHERE ISDATE([date])=0 OR ISDATE([time])=0-- Show all Good datetime valuesSELECT * FROM myTable99 WHERE ISDATE([date])=1 AND ISDATE([time])=1--Update the ColumnUPDATE myTable99 SET [datetime] = CONVERT(datetime,[date]+' '+[time]) FROM myTable99 WHERE ISDATE([date])=1 AND ISDATE([time])=1-- Have a lookSELECT * FROM myTable99GO--Cleanup this messSET NOCOUNT OFFDROP TABLE myTable99GO[/code]Brett8-) |
 |
|
|
|
|
|