-1

I need to make the rows in a table appear in columns in sql server as Im recording peoples annual leave - the users want what ive created in .net to appear like in their spreadsheets hence why im doing this. I have heard that you can use a PIVOT table.I have a select statement below:

select 
typeID,
datesFrom,
datesTo
from availability

where authno = 24

Which returns the below:

+--------+-------------------------+-------------------------+
| typeID |        datesFrom        |         datesTo         |
+--------+-------------------------+-------------------------+
|      1 | 2015-02-16 00:00:00.000 | 2015-02-23 00:00:00.000 |
|      2 | 2015-06-23 00:00:00.000 | 2015-06-29 00:00:00.000 |
+--------+-------------------------+-------------------------+

but my problem is that I need it to appear like below:

+--------+---------------------+-------------------+--------+-----------------+---------------+
| typeID | datesFrom(February) | datesTo(February) | typeID | datesFrom(June) | datesTo(June) |
+--------+---------------------+-------------------+--------+-----------------+---------------+
|      1 | 16/02/2015          | 23/02/2015        |      2 | 23/06/2015      | 29/06/2015    |
|        |                     |                   |        |                 |               |
+--------+---------------------+-------------------+--------+-----------------+---------------+

Any help is greatly, greatly appreciated. I havent been able to find a pivot which shows dates like this

wubblyjuggly
  • 899
  • 3
  • 13
  • 33
  • 2
    Its amazing how many times this question is asked. Maybe if you just google before asking somebody else to help you, you might find that the answer has been there all along. http://stackoverflow.com/questions/18026236/sql-server-columns-to-rows is just one of them – Jaques Feb 23 '15 at 11:01
  • First comment is UNPIVOT so not useful for me and the second comment doesnt handle dates in it – wubblyjuggly Feb 23 '15 at 11:44

1 Answers1

-1

You're looking for pivot and unpivot. https://technet.microsoft.com/en-us/library/ms177410%28v=sql.105%29.aspx

user1671538
  • 143
  • 3
  • 11