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
Teraz używam poniżej Pivot, aby uzyskać wynikJak przestawić liczbę punch razy dziennie na serwerze sql 2005?
SELECT * FROM
(
SELECT strcardid,SwipeDate,PunchTime FROM ALL_PUNCHES_PIVOT2
) P
PIVOT (
min([PunchTime]) FOR SwipeDate in ([01/08/2013])
) as Pvt
Poniżej jest wynikiem jestem coraz
strcardid 01/08/2013
3716817970 08:47:53
jaki kiedykolwiek chcę wyjście jak poniżej
strcardid Swipedate time1 time2 time3 time4 time5 time6
3716817970 01/08/2013 08:47:53 08:47:56 08:52:29 08:52:31 17:50:14 17:50:17
Proszę mi pomóc w tej sprawie
Czy liczba kolumn "timeX' jest stała? Lub może być 'time100, ....' – valex
czas jest Max 15 – user3012724