T-SQL语句有问题请教 CREATE TABLE #TMP
(
ID INT IDENTITY(1,1),
USERID INT,
INDATE DATE,
OUTDATE DATE,
INDATETIME DATETIME,
OUTDATETIME DATETIME
)
INSERT INTO #TMP VALUES( 1,'2014-04-22','2014-04-22','2014-04-22 9:01',NULL)
INSERT INTO #TMP VALUES( 1,'2014-04-22','2014-04-22','2014-04-22 9:02',NULL)
INSERT INTO #TMP VALUES( 1,'2014-04-22','2014-04-22','2014-04-22 9:03',NULL)
INSERT INTO #TMP VALUES( 1,'2014-04-22','2014-04-22','2014-04-22 9:05','2014-04-22 10:00')
INSERT INTO #TMP VALUES( 1,'2014-04-22','2014-04-22',NULL,'2014-04-22 10:05')
INSERT INTO #TMP VALUES( 1,'2014-04-22','2014-04-22','2014-04-22 10:30',NULL)
INSERT INTO #TMP VALUES( 1,'2014-04-22','2014-04-22','2014-04-22 10:35','2014-04-22 11:00')
INSERT INTO #TMP VALUES( 1,'2014-04-23','2014-04-23','2014-04-23 13:00',NULL)
INSERT INTO #TMP VALUES( 1,'2014-04-23','2014-04-23','2014-04-23 13:20',NULL)
INSERT INTO #TMP VALUES( 1,'2014-04-23','2014-04-23','2014-04-23 13:20','2014-04-23 13:59')
INSERT INTO #TMP VALUES( 1,'2014-04-23','2014-04-23',NULL,'2014-04-23 14:00')
SELECT * FROM #TMP
--要实现的效果
SELECT 1,'2014-04-22','2014-04-22','2014-04-22 9:01','2014-04-22 10:05'
UNION ALL
SELECT 1,'2014-04-22','2014-04-22','2014-04-22 10:30','2014-04-22 11:00'
UNION ALL
SELECT 1,'2014-04-23','2014-04-23','2014-04-23 13:00','2014-04-23 14:00'