Display select items in horizontal way

  • Select * from table will display items in vertical way in studio.
    How to make the statement to list items in horizontal way?
    For example, the code below will display like

    Select * from order

    [column1],
    [column2],
    ...
    [column15],

    How to make like below

    [column1],[column2],...[column15],

  • adonetok - Tuesday, July 24, 2018 11:58 AM

    Select * from table will display items in vertical way in studio.
    How to make the statement to list items in horizontal way?
    For example, the code below will display like

    Select * from order

    [column1],
    [column2],
    ...
    [column15],

    How to make like below

    [column1],[column2],...[column15],

    Are you talking bout the code itself?

  • Yes, I want to get result in SQL studio.
    I already knew how to copy to Excel to change it.

  • adonetok - Tuesday, July 24, 2018 1:35 PM

    Yes, I want to get result in SQL studio.
    I already knew how to copy to Excel to change it.

    Still lost.  If you run this: Select * from order in SSMS, the results pane will have the columns across the top and the rows going down.  From what you posted are you talking about how the code is displayed in a SSMS query window?  If so, how are you generating the code?

  • adonetok - Tuesday, July 24, 2018 11:58 AM

    Select * from table will display items in vertical way in studio.
    How to make the statement to list items in horizontal way?
    For example, the code below will display like

    Select * from order

    [column1],
    [column2],
    ...
    [column15],

    How to make like below

    [column1],[column2],...[column15],

    Take a look at Using PIVOT and UNPIVOT

  • DesNorton - Tuesday, July 24, 2018 10:21 PM

    adonetok - Tuesday, July 24, 2018 11:58 AM

    Select * from table will display items in vertical way in studio.
    How to make the statement to list items in horizontal way?
    For example, the code below will display like

    Select * from order

    [column1],
    [column2],
    ...
    [column15],

    How to make like below

    [column1],[column2],...[column15],

    Take a look at Using PIVOT and UNPIVOT

    Neither PIVOT nor UNPIVOT can turn the entire table on its side.   I'm more interested in WHY the OP has a need for this.   The easiest way to do that is to use a reporting tool.   However, doing it in SQL Server Management Studio requires a CROSSTAB type of query, and I'm not sure it's even worth doing to get the entire table to display the opposite way.   On the other hand, if the user just wants a SELECT statement to appear with the columns listed across, that's a matter of just scripting the table as a SELECT and then deleting the line breaks.   As the OP's post isn't terribly clear on exactly what he/she might want, who knows...

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • sgmunson - Wednesday, July 25, 2018 3:51 PM

    DesNorton - Tuesday, July 24, 2018 10:21 PM

    adonetok - Tuesday, July 24, 2018 11:58 AM

    Select * from table will display items in vertical way in studio.
    How to make the statement to list items in horizontal way?
    For example, the code below will display like

    Select * from order

    [column1],
    [column2],
    ...
    [column15],

    How to make like below

    [column1],[column2],...[column15],

    Take a look at Using PIVOT and UNPIVOT

    Neither PIVOT nor UNPIVOT can turn the entire table on its side.   I'm more interested in WHY the OP has a need for this.   The easiest way to do that is to use a reporting tool.   However, doing it in SQL Server Management Studio requires a CROSSTAB type of query, and I'm not sure it's even worth doing to get the entire table to display the opposite way.   On the other hand, if the user just wants a SELECT statement to appear with the columns listed across, that's a matter of just scripting the table as a SELECT and then deleting the line breaks.   As the OP's post isn't terribly clear on exactly what he/she might want, who knows...

    If the OP is talking about the output from the simple query showing each column on a single row, where and how is this being done?  I have never seen this as a form of output when running a query in SSMS.

  • adonetok - Tuesday, July 24, 2018 11:58 AM

    Select * from table will display items in vertical way in studio.
    How to make the statement to list items in horizontal way?
    For example, the code below will display like

    Select * from order

    [column1],
    [column2],
    ...
    [column15],

    How to make like below

    [column1],[column2],...[column15],

    The confusion on this thread might be because it looks like you're using the word "column" instead of "row".  Is that a possibility?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply