日期:2014-05-17 浏览次数:20489 次
IF OBJECT_ID('test1') IS NOT NULL
DROP TABLE test1 ;
CREATE TABLE test1
(
ID INT,
MyDateTime NVARCHAR(22)
)
INSERT INTO test1
SELECT 1,'2008101800'
UNION
SELECT 2,'2008101801'
UNION
SELECT 3,'2008101802'
UNION
SELECT 4,'2008101803'
IF NOT OBJECT_ID('#a') IS NOT NULL
DROP TABLE #a
SELECT ID ,
MyDateTime ,
DATEADD(HOUR
, CONVERT(INT, RIGHT(MyDateTime, 2)),CONVERT(DATETIME, LEFT(MyDateTime, 8))
) AS 'datetime' ,
CONVERT(NVARCHAR(30)
, DATEADD(HOUR, -1,DATEADD(HOUR,CONVERT(INT, RIGHT(MyDateTime, 2)),CONVERT(DATETIME, LEFT(MyDateTime,8))))
, 20) AS 'reduce'
INTO #a
FROM test1
SELECT * FROM #a
SELECT ID,
MyDateTime,
LEFT(REPLACE(REPLACE(reduce,'-',''),' ',''),10)
FROM #a