Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Display Rows Vertically or Alphabetically

By William Talada,

The first included script creates a procedure that displays a single row from a table vertically in alphabetical order with a column name and value in each row of the result set. This procedure is very handy when a table contains hundreds of columns ordered quite randomly. This will save you hours wasted per week simly trying to find a particular column in resultsets.

The second included script will do a standard "select" returning many rows but with all columns in alphabetical order. I haven't updated these to work with schemas other than the default one but most people are using dbo anyway.

To call these, supply a table name and a "where" clause as in the following example:

exec AzDisplay Customer, ''CustomerKey = 123'

exec AzSelect Customer, ''CustomerKey = 123'

My purpose in submitting these procedures is to show that key features are missing in SSMS that other products have such as dBASE and Sybase add-ons. One constant irritation for me in the SSMS Query window is the lack of commands in SQLCMD mode to control output directly such as having some result sets display as text and others as grids and others as vertical rows with or without headings and others with columns in alphabetical or type order.


Total article views: 2776 | Views in the last 30 days: 3
Related Articles

Display the columns in Alphabetical order in 2005 Management Studio?

How to display the columns of a table in alphabetical order in 2005 Management Studio?


Auto Increment Alphabet

How to iIncrement an alphabet by the next alphabet


Order one column alphabetically while keeping a Total Line Footer at Bottom of Table

A Union Query in Access 2003 produces the Sum of a Count, but Column cannot be ordered


Alter column order

Alter column order


Order by specific word, then alphabetically

Order by specific word, then aplhabetically


Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones