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

By Steve McRoberts,

When you have a table with many columns, it can become a chore to remember all of the column names and find what you need. This script displays the selected rows vertically with the columns in alpha order to help locate columns when you don't know the exact names (or if you just want to see all the columns without scrolling horizontally). This uses SQL Server 2005's UNPIVOT command, and so will not work in SQL 2000.

It will not display columns having null values or columns of type text, ntext, image, or timestamp.

 

It takes two parameters, the second of which is optional: tablename (in single-quotes) and an optional Where clause in quotes (including the word WHERE).

 

For example:

vselect 'mytable', 'where id=123'

 

Total article views: 1821 | Views in the last 30 days: 1
 
Related Articles
FORUM

Using column alias in my where filter

Using column alias in my where filter

FORUM

Use Table Column Contents As Where Clause

Need to use SQL snippet contained in table column as Where Clause

FORUM

Use Table Column Contents As Where Clause

Need to use SQL snippet contained in table column as Where Clause

BLOG

Column alias in order by and where

If you ever wonder why column alias can be used in order by and not in where clause, it’s the...

FORUM

Select Where Any Column Equals (or Like) Value

Select row(s) where any of the column names in table equals a value

Tags
columns    
information_schema    
select    
unpivot    
 
Contribute

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
Editor, SQLServerCentral.com

Already a member? Jump in:

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