Jed Monsanto
Jed Monsanto

Reputation: 86

SQL- How to put your Row result as a column

I Have a script that has a result of 3 rows only:

SELECT U.LEVEL FROM USER U

 1. ADMINISTRATOR
 2. STANDARD USER
 3. LIMITED USER

Now what i want is to look like as a column in the result of the script. please see below:

ADMINISTRATOR | STANDARD USER | LIMITED USER

THANK YOU IN ADVANCE

Upvotes: 0

Views: 32

Answers (1)

Giannis Paraskevopoulos
Giannis Paraskevopoulos

Reputation: 18411

I guess your question is not complete. You stated you wanted them to be the column names, but have not said what values you like. With your input, the following is a possible solution:

SELECT *
FROM (
         SELECT [LEVEL]
         FROM [USER]
     ) AS SourceTable
PIVOT(
         MAX([LEVEL])
         FOR [LEVEL] IN ([ADMINISTRATOR], [STANDARD USER], [LIMITED USER])
     ) AS PivotTable;

SQL Fiddle Demo

Upvotes: 1

Related Questions