Skip to content
Advertisement

I’m looking for a right solution to achieve the below scenario in SQL Server

I’ve a result set from a query like this below

Court_id from to Available
7 6:00:00 7:00:00 Yes
7 7:00:00 8:00:00 No
7 8:00:00 9:00:00 Yes
8 6:00:00 7:00:00 Yes
8 7:00:00 8:00:00 Yes
8 8:00:00 9:00:00 No
9 6:00:00 7:00:00 Yes
9 7:00:00 8:00:00 Yes
9 8:00:00 9:00:00 No

How can I achieve in column wise like below from the above result ?

from to 7 8 9
6:00:00 7:00:00 Yes Yes Yes
7:00:00 8:00:00 no Yes Yes
8:00:00 9:00:00 Yes no no

Court_id can change time to time.

I’ve tried the following

Advertisement

Answer

You are pivoting the wrong columns:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement