Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to label queries?

Posted on 2011-09-23
7
Medium Priority
?
344 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 61

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 61

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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 1000 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 1000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

926 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