Select "Rows as Columns" in SELECT

Possible duplicate:
How to select columns as rows?

I have a table with identifiers like

Table ------- 1 2 3 4 5 and so on 

I have this request,

SELECT A, B, Here I need to SELECT ID as a column , FROM MyTable

So the result of this will be

  AB 1 2 3 4 5 6 7 and so on ----------------------------------- 
+4
source share
2 answers

You need a cross-tab query. Check this out: http://www.simple-talk.com/sql/t-sql-programming/creating-cross-tab-queries-and-pivot-tables-in-sql/

It explains how to perform a simple cross-reference request, which might be all you need. However, it looks like you can also use the stored procedure created by the author to overcome some of the drawbacks of the cross tab request.

+4
source

You have an answer already in SO :)

Look here or here . When you fill out a question, pay attention, usually it gives you similar questions :)

+4
source

Source: https://habr.com/ru/post/1381263/


All Articles