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

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

Display results VERTICALLY in Results window

By D Simmons,

DESCRIPTION:
This procedure will allow you to display results vertically (down) instead of across the screen. It's great when you are dealing with a query that has 50 columns and just a couple of records.

LIMITATIONS:
* It will be very slow if you are trying to return a lot of records. Works best for queries returning 10 or less records.
* It displays the DATALENGTH for text and image fields

INSTRUCTIONS:
Basically build your query with as many inner joins as needed.

1. Load the sp_SHOWDOWN query into the master database or a local database.
2. Execute the following query: sp_SHOWDOWN 1
3. This will display syntax and the 3 lines you'll need to add to your query.
4. Modify the query as instructed and execute again
5. Results are now vertical!

EXAMPLE: (using pubs database)
IF OBJECT_ID('tempdb..#tempwide') IS NOT NULL DROP TABLE #tempwide

select top 1 a.au_id 'a.au_id', a.au_lname 'a.au_lname', a.au_fname 'a.au_fname', a.phone 'a.phone', a.address 'a.address', a.city 'a.city', a.state 'a.state', a.zip 'a.zip', a.contract 'a.contract',
ta.au_id 'ta.au_id', ta.title_id 'ta.title_id', ta.au_ord 'ta.au_ord', ta.royaltyper 'ta.royaltyper',
t.title_id 't.title_id', t.title 't.title', t.type 't.type', t.pub_id 't.pub_id', t.price 't.price', t.advance 't.advance', t.royalty 't.royalty', t.ytd_sales 't.ytd_sales', t.notes 't.notes', t.pubdate 't.pubdate'
INTO #tempwide
from authors a
inner join titleauthor ta ON a.au_id = ta.au_id
inner join titles t ON t.title_id = ta.title_id

EXEC sp_SHOWDOWN

I certainly didn't type all those field names in the SELECT above. I used _SELECT (also contributed by me) to produce unique fieldnames for each table

Please feel free to modify to fit your needs.

Total article views: 710 | Views in the last 30 days: 4
 
Related Articles
FORUM

display permissions with database name

want to display the database name with the user's permissions

FORUM

Display Query Execution Plan - SQL Server 2005

Display Query Execution Plan - SQL Server 2005

FORUM

Displaying dates in Name and dd-mm-yyyy

Query on Displaying dates

FORUM

database query

query database and instancename

FORUM

SQL 2008 query result message tab display limit

SQL 2008 query result message tab display max limit

Tags
miscellaneous    
t-sql    
 
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