CREATE TABLE ALL_PUNCHES_PIVOT2 (ID INT,strcardid NVARCHAR(100),SwipeDate VARCHAR(60),TIME VARCHAR(40));
INSERT INTO ALL_PUNCHES_PIVOT2 (ID,strcardid,SwipeDate,PUNCHTIME)
VALUES (1,'3716817970','01/08/2013','08:47:53')
INSERT INTO ALL_PUNCHES_PIVOT2 (ID,strcardid,SwipeDate,PUNCHTIME)
VALUES (2,'3716817970','01/08/2013','08:47:56')
INSERT INTO ALL_PUNCHES_PIVOT2 (ID,strcardid,SwipeDate,PUNCHTIME)
VALUES (3,'3716817970','01/08/2013','08:52:29')
INSERT INTO ALL_PUNCHES_PIVOT2 (ID,strcardid,SwipeDate,PUNCHTIME)
VALUES (4,'3716817970','01/08/2013','08:52:31')
INSERT INTO ALL_PUNCHES_PIVOT2 (ID,strcardid,SwipeDate,PUNCHTIME)
VALUES (5,'3716817970','01/08/2013','17:50:14')
INSERT INTO ALL_PUNCHES_PIVOT2 (ID,strcardid,SwipeDate,PUNCHTIME)
VALUES (6,'3716817970','01/08/2013','17:50:17')
SELECT * FROM ALL_PUNCHES_PIVOT2;
ID strcardid SwipeDate PunchTime
1 3716817970 01/08/2013 08:47:53
2 3716817970 01/08/2013 08:47:56
3 3716817970 01/08/2013 08:52:29
4 3716817970 01/08/2013 08:52:31
5 3716817970 01/08/2013 17:50:14
6 3716817970 01/08/2013 17:50:17
Run Code Online (Sandbox Code Playgroud)
现在我使用下面的Pivot来获得结果
SELECT * FROM …Run Code Online (Sandbox Code Playgroud)