SQL Server 2000
Here's my SQL:
Set Nocount On
DECLARE @STAFF INT
SET @STAFF = '100'
SELECT planev.pl_staff,
(CONVERT(VARCHAR(10), planev.pl_date, 101)) + ' ' +
(CONVERT(VARCHAR(5), planev.pl_time, 8)) as FirstTime,
(SELECT Min((CONVERT(VARCHAR(10), planev_1.pl_date, 101)) + ' ' + (CONVERT(VARCHAR(5), planev_1.pl_time, 8)))
FROM planev INNER JOIN planev planev_1 ON planev.pl_staff = planev_1.pl_staff
WHERE
(CONVERT(VARCHAR(10), planev_1.pl_date, 101)) + ' ' + (CONVERT(VARCHAR(5), planev_1.pl_time, 8))>
(CONVERT(VARCHAR(10), planev.pl_date, 101)) + ' ' + (CONVERT(VARCHAR(5), planev.pl_time, 8))
and (planev.pl_staff = @STAFF) ) as EndTime
FROM planev
WHERE (planev.pl_staff = @STAFF)
Set NoCount Off
Here's the Results:
pl_staff FirstTime EndTime
100 03/26/2007 08:00 03/26/2007 10:00
100 03/26/2007 10:00 03/26/2007 10:00
100 04/02/2007 10:00 03/26/2007 10:00
100 04/03/2007 11:00 03/26/2007 10:00
100 04/04/2007 09:00 03/26/2007 10:00
100 04/05/2007 13:00 03/26/2007 10:00
100 04/05/2007 15:00 03/26/2007 10:00
100 04/05/2007 16:00 03/26/2007 10:00
100 04/09/2007 09:00 03/26/2007 10:00
100 04/09/2007 10:00 03/26/2007 10:00
The desired end result:
pl_staff FirstTime EndTime
100 03/26/2007 08:00 03/26/2007 10:00
100 03/26/2007 10:00 04/02/2007 10:00
100 04/02/2007 10:00 04/03/2007 11:00
100 04/03/2007 11:00 04/04/2007 09:00
100 04/04/2007 09:00 04/05/2007 13:00
100 04/05/2007 13:00 04/05/2007 15:00
100 04/05/2007 15:00 04/05/2007 16:00
100 04/05/2007 16:00 04/09/2007 09:00
100 04/09/2007 09:00 04/09/2007 10:00
100 04/09/2007 10:00 04/09/2007 13:00
I'm close. I know it's getting the Min corectly for the staff, but I need it to choose the next date.
Here's my SQL:
Set Nocount On
DECLARE @STAFF INT
SET @STAFF = '100'
SELECT planev.pl_staff,
(CONVERT(VARCHAR(10), planev.pl_date, 101)) + ' ' +
(CONVERT(VARCHAR(5), planev.pl_time, 8)) as FirstTime,
(SELECT Min((CONVERT(VARCHAR(10), planev_1.pl_date, 101)) + ' ' + (CONVERT(VARCHAR(5), planev_1.pl_time, 8)))
FROM planev INNER JOIN planev planev_1 ON planev.pl_staff = planev_1.pl_staff
WHERE
(CONVERT(VARCHAR(10), planev_1.pl_date, 101)) + ' ' + (CONVERT(VARCHAR(5), planev_1.pl_time, 8))>
(CONVERT(VARCHAR(10), planev.pl_date, 101)) + ' ' + (CONVERT(VARCHAR(5), planev.pl_time, 8))
and (planev.pl_staff = @STAFF) ) as EndTime
FROM planev
WHERE (planev.pl_staff = @STAFF)
Set NoCount Off
Here's the Results:
pl_staff FirstTime EndTime
100 03/26/2007 08:00 03/26/2007 10:00
100 03/26/2007 10:00 03/26/2007 10:00
100 04/02/2007 10:00 03/26/2007 10:00
100 04/03/2007 11:00 03/26/2007 10:00
100 04/04/2007 09:00 03/26/2007 10:00
100 04/05/2007 13:00 03/26/2007 10:00
100 04/05/2007 15:00 03/26/2007 10:00
100 04/05/2007 16:00 03/26/2007 10:00
100 04/09/2007 09:00 03/26/2007 10:00
100 04/09/2007 10:00 03/26/2007 10:00
The desired end result:
pl_staff FirstTime EndTime
100 03/26/2007 08:00 03/26/2007 10:00
100 03/26/2007 10:00 04/02/2007 10:00
100 04/02/2007 10:00 04/03/2007 11:00
100 04/03/2007 11:00 04/04/2007 09:00
100 04/04/2007 09:00 04/05/2007 13:00
100 04/05/2007 13:00 04/05/2007 15:00
100 04/05/2007 15:00 04/05/2007 16:00
100 04/05/2007 16:00 04/09/2007 09:00
100 04/09/2007 09:00 04/09/2007 10:00
100 04/09/2007 10:00 04/09/2007 13:00
I'm close. I know it's getting the Min corectly for the staff, but I need it to choose the next date.