Sean, here's how you can do this:
SELECT
CASE WHEN ISDATE(dtstr) = 1 THEN CAST(dtstr AS DATETIME) END AS dt,
other_columns
FROM (SELECT OrigTrxDate + ' '
+ SUBSTRING(OrigTrxTime, 1, 2) + ':'
+ SUBSTRING(OrigTrxTime, 3, 2) + ':'
+ SUBSTRING(OrigTrxTime, 5, 2) AS dtstr,
other_columns
FROM YourTable) AS D
--
BG, SQL Server MVP
www.SolidQualityLearning.com
"Sean" <Sean (AT) discussions (DOT) microsoft.com> wrote
Quote:
I have 2 varchar fields, OrigTrxDate and OrigTrxTime. The value is 031027
and
103520. I want to get a combined datetime field with the value 2003-10-27
10:35:20.000 if they are both valid value. How can I do in SQL?
Thanks. |