Solved

How to label queries?

Posted on 2011-09-23
7
326 Views
Last Modified: 2012-05-12
In Management Studio results tab, how do I give each query a header or label?  When a few queries are printing their results, it can be confusing to know which query is which.
0
Comment
Question by:brettr
7 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 36589192
SSMS is really stupid... you cannot rename TABS, and after a while you cannot find which one is what and which server it is running on... and the expand icon does not help either if you have, say more than 6 open tabs... MS should update this tool, they can chack how Quest - TOAD implemented this...
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 36589668
The only way to do it really is to save the SQL script you are running.  I use the MDI interace as opposed to Tabbed and makes it easy to go into the Windows list and see what is running, where, and what it's called.
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 36589700
saving is not an option for me :) when I work wit SQL I always create new queries test something and close re-open new windows... I dont want to save all my garbage queries :) but if we save them as "Setup" for example, tab name shows "c:\path_to_file\Setup.sql - DBNAME" :) maybe this option is better than nothing...
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:brettr
ID: 36589887
I think you guys are talking about something completely different.  You keep talking about TABS.  I'm in one window with a corresponding results tab.  That tab is fine and no concern.  In the results tab, I have 5 result sets.  I cannot tell which result set goes to which query.  I just want some type of name to correspond to each result set so I can point it back to the query that generated it.
0
 
LVL 39

Expert Comment

by:BrandonGalderisi
ID: 36589890
Trust me.  I know.  My current session of SSMS is at #163 for new query windows created.  I'm just offering a suggestion which I have found useful for queries that I am bouncing back and forth between.  Quick open/close queries don't need to be named.  It's the ones that you are working on, tweaking, running, coming back to.  Have you ever have SSMS crash?  I have, and lost several queries in progress that the recovery couldn't get.  That's why for anything I'm going to keep around for longer than a minute or two I save it.
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 250 total points
ID: 36589916
Ahh..  Yeah, we're talking about something completely different.

For that, if just need a quick label, I do a select above the real select to describe it.

Ex.

Select 'Next result is result of A join B'
select * from A inner join B on a.some1 = b.some1

When working with temp tables in debugging mode I have a different approach.


select '#Test' as '#Test',* from #Test



0
 
LVL 9

Assisted Solution

by:anillucky31
anillucky31 earned 250 total points
ID: 36597202
There is no direct way to do it. You can modify your queries. You can add custom Column in each of your query and can give it static value and column name.

For Example

select 'Query1' as Query1, col1, col2 from yourtable
select 'Query2' as Query2, col1, col2 from yourtable
.
...

..
Like this when you will see your result in result pane you can identify by first column from which query this result has come.


I hope this will help you.
 
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now