1 DECLARE cursor_timeformatter CURSOR LOCAL FOR 2 SELECT ID, PublishTime FROM Book_BaseFields 3 OPEN cursor_timeformatter 4 DECLARE @ID int 5 DECLARE @PublishTime nvarchar(50) 6 WHILE @@FETCH_STATUS=0 7 BEGIN 8 FETCH NEXT FROM cursor_timeformatter INTO @ID, @PublishTime 9 IF((Len(@PublishTime)-Len(Replace(@PublishTime,'-','')))=2) 10 BEGIN 11 UPDATE Book_BaseFields SET PublishTime = CONVERT(varchar(100),CAST(@PublishTime as DATETIME),23) WHERE ID=@ID 12 END 13 ELSE IF((Len(@PublishTime)-Len(Replace(@PublishTime,'-','')))=1) 14 BEGIN 15 IF(LEN(SUBSTRING(@PublishTime,6,2))=1) 16 BEGIN 17 UPDATE Book_BaseFields SET PublishTime = SUBSTRING(@PublishTime,1,5)+'0'+SUBSTRING(@PublishTime,6,2) WHERE ID=@ID 18 END 19 END 20 END 21 CLOSE cursor_timeformatter 22 DEALLOCATE cursor_timeformatter 23 GO