我是新人,所以我确定我完全搞砸了如何做到这一点。我提前道歉......
我有一个中继器,每天输出时间卡拳。数据来自具有如下结构的数据库。当我在Repeater中输出数据时,它只是不断添加数据
有没有办法输出以下数据:
SELECT PunchId, PunchIn, PunchOut, PunchDay, WeekEnding
FROM TimePunches
WHERE WeekEnding = @WeekEnding
PunchId PunchIn PunchOut PunchDay WeekEnding
1 09:00 AM 03:35 PM 2 06/07/2014
2 08:34 AM 09:11 AM 4 06/07/2014
3 09:11 AM 09:20 AM 4 06/07/2014
4 09:20 AM 05:20 PM 4 06/07/2014
5 08:33 AM 11:46 AM 5 06/07/2014
6 12:12 PM 05:19 PM 5 06/07/2014
7 05:25 PM 06:19 PM 5 06/07/2014
8 07:25 PM 09:01 PM 5 06/07/2014
显示为:
Sun Mon Tue Wed Thr Fri Sat
09:00 AM 08:34 AM 08:33 AM
03:35 PM 09:11 AM 11:46 AM
09:11 AM 12:12 PM
09:20 AM 05:19 PM
09:20 AM 05:25 PM
05:10 PM 06:19 PM
07:25 PM
09:01 PM
目前它正在做这个不好的事情
Sun Mon Tue Wed Thr Fri Sat
09:00 AM
03:35 PM
08:34 AM
09:11 AM
09:11 AM
09:20 AM
09:20 AM
05:10 PM
08:33 AM
11:46 AM
12:12 PM
05:19 PM
05:25 PM
06:19 PM
07:25 PM
09:01 PM
我非常确定这是一个相当简单的方法,我只是在思考它。任何帮助都会很棒。
答案 0 :(得分:1)
SELECT
[1] Sun, [2] Mon, [3] Tue, [4] Wed, [5] Thr, [6] Fri, [7] Sat
FROM (
SELECT
PunchTime,
PunchDay,
ROW_NUMBER() OVER(PARTITION BY PunchDay ORDER BY PunchTime) RowNumber
FROM @t
UNPIVOT(PunchTime for PunchType in (PunchIn,PunchOut) ) t1
) t2
PIVOT(MAX(PunchTime) FOR PunchDay IN ([1],[2],[3],[4],[5],[6],[7]) ) t3