|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, March 21, 2013 10:59 AM
Points: 22,
Visits: 75
|
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Monday, March 18, 2013 5:11 AM
Points: 139,
Visits: 143
|
|
Hi,
Try this instead, works just as well. Basically I insert a space between the Date and the time and a : between the hours and the minutes
declare @DtStr varchar(20) set @DtStr='200907011020' select convert(datetime,substring(@DtStr,1,8)+' '+substring(@DtStr,9,2)+':'+substring(@DtStr,11,2))
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Yesterday @ 6:33 PM
Points: 32,889,
Visits: 26,757
|
|
Ummm... CONVERT is relatively expensive and so are all of the substrings not to mention the use of a UDF...
SELECT CAST(STUFF(STUFF('200907111400',11,0,':'),9,0,' ') AS DATETIME)
--Jeff Moden "RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following... http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following... http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Thursday, March 21, 2013 10:59 AM
Points: 22,
Visits: 75
|
|
| tks to all. both suggestions are good.
|
|
|
|