January 8, 2016 at 2:53 am
HI,
Here is the new test data in the correct format.
INSERT INTO [TblAppointments]
([ClientID],[ApptDate],[ApptTime],[StaffID],[Duration])
VALUES
(2528,'10/01/2016','10:00',22011063, 30),
(2528,'11/01/2016','10:00',22011063, 30),
(2528,'12/01/2016','10:00',22011063, 30),
(2528,'13/01/2016','10:00',22011063, 30),
(2528,'14/01/2016','10:00',22011063, 30),
(2528,'15/01/2016','10:00',22011063, 30),
(2528,'16/01/2016','10:00',22011063, 30),
(2528,'17/01/2016','10:00',22011063, 30),
(2528,'10/01/2016','15:00',22011063, 45),
(2528,'12/01/2016','15:00',22011063, 45),
(2528,'13/01/2016','15:00',22011063, 45),
(2528,'14/01/2016','15:00',22011063, 45),
(2528,'15/01/2016','15:00',22011063, 45),
(2528,'16/01/2016','15:00',22011063, 45),
(2528,'17/01/2016','15:00',22011063, 45),
(2528,'10/01/2016','10:00',22016486, 30),
(2528,'11/01/2016','10:00',22016486, 30),
(2528,'12/01/2016','10:00',22016486, 30),
(2528,'13/01/2016','10:00',22016486, 30),
(2528,'14/01/2016','10:00',22016486, 30),
(2528,'16/01/2016','10:00',22016486, 30),
(2528,'17/01/2016','10:00',22016486, 30)
January 8, 2016 at 4:41 am
Tallboy (1/7/2016)
Hi Folks;Jeffs code ran brilliantly until changed my test data and added two appointment rows for the same client with same date and times data but with different StaffID's.
The result is the MAX get the highest StaffID I think! and ignores the the other row, whereas I want the crosstab to show 2 rows for each date and time but different StaffID's in the middle.
New test data is here...
2528,'10/01/2016','10:00',22011063, 30
2528,'11/01/2016','10:00',22011063, 30,
2528,'12/01/2016','10:00',22011063, 30
2528,'13/01/2016','10:00',22011063, 30
2528,'14/01/2016','10:00',22011063, 30
2528,'15/01/2016','10:00',22011063, 30
2528,'16/01/2016','10:00',22011063, 30
2528,'17/01/2016','10:00',22011063, 30
2528,'10/01/2016','15:00',22011063, 45
2528,'11/01/2016','15:00',22011063, 45
2528,'12/01/2016','15:00',22011063, 45
2528,'13/01/2016','15:00',22011063, 45
2528,'14/01/2016','15:00',22011063, 45
2528,'15/01/2016','15:00',22011063, 45
2528,'16/01/2016','15:00',22011063, 45
2528,'17/01/2016','15:00',22011063, 45
2528,'10/01/2016','10:00',22016486, 30
2528,'11/01/2016','10:00',22016486, 30
2528,'12/01/2016','10:00',22016486, 30
2528,'13/01/2016','10:00',22016486, 30
2528,'14/01/2016','10:00',22016486, 30
2528,'15/01/2016','10:00',22016486, 30
2528,'16/01/2016','10:00',22016486, 30
2528,'17/01/2016','10:00',22016486, 30
add another column to your view
ROW_NUMBER() OVER (partition BY ClientID, ApptDate, ApptTime
ORDER BY StaffID) AS rn
edit the proc to read as
+'
FROM VwAppointments1 appt
WHERE appt.ApptDate >= @pSDate
AND appt.ApptDate < DATEADD(dd,1,@pEDate)
AND appt.ClientID = @pClientID
GROUP BY appt.ApptTime, appt.rn
ORDER BY appt.ApptTime, appt.rn;
'
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
January 8, 2016 at 5:12 am
Exactly. Thanks for the early morning cover, Graham.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 8, 2016 at 12:32 pm
Thanks guys looks good..
Tried and appears to Work Brilliant !!!!:-D:-D:-D:-D
January 8, 2016 at 7:33 pm
Tallboy (1/8/2016)
Thanks guys looks good..Tried and appears to Work Brilliant !!!!:-D:-D:-D:-D
Thanks for the feedback. To finish this off, do you understand it all well enough to be able to maintain it if the need should arise?
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 16 through 19 (of 19 total)
You must be logged in to reply to this topic. Login to reply