Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

Wednesday, February 1, 2012

Show/Hide Results Pane – SQL Server 2008

A few years back I wrote an article about doing this same thing in SQL Server 2005.  All the images from the previous post were somehow lost, and since the instructions are basically the same for SQL 2008 I thought it would be a nice refresher.

One of the simplest and most useful features when debugging a sql script is to be able to run your query to see some results, then hide the results pane to continue tweaking your sql code. This feature was a button on the toolbar in Query Analyzer in SQL Server 2000, but for some reason it has been missing in SSMS (SQL Server Management Studio) since 2005. Well, the button may not exist by default, but it's easy to add it in.

This is what we are striving for, a button on the SQL Editor toolbar that says either "Show Results Pane" or "Hide Results Pane":


To add a button to hide the results pane:

1. Click on the little down-arrow at the end of a toolbar and choose "Add or Remove Buttons", then choose "Customize...":
Add button to Toolbar


2. The Customize dialog window will open with the "Commands" tab selected. Now we only need to find the command we are looking for. Under "Categories:", choose "Window". Then under "Commands:", find the command "Show Results Pane":

Choosing the "Show Results Pane" command from the menus


 3. Once you have located the "Show Results Pane" command, you have to click and drag it to where you want it to be located on the toolbar:

Starting the drag


Placing on toolbar



End result after placement

Originally I had my button located on the Standard toolbar, but eventually I figured out it made more sense to add it to the SQL Editor toolbar. It's pretty easy to find the SQL Editor toolbar - it only displays when you are working in a query window.


Here is the end result again:

Notice the button says "Hide Results Pane" when the results pane is showing:
"Hide Results Pane" Button


Also notice that the button says "Show Results Pane" when the results pane is hidden:
"Show Results Pane" Button




Sunday, March 16, 2008

SSRS code examples

I use SQL Server 2005 Report Services (SSRS) quite a bit. I thought I'd share some code examples I keep handy.


First day of Month
To get the first day of the current month:
=CDate(Month(Today).ToString() & "/1/" & Year(Today).ToString())


Last day of Month
To get the last day of the current month (use first day of the next month and subtract one):
=DateAdd("d",-1,DateAdd("m",1,CDate(Month(Today).ToString() & "/1/" & Year(Today).ToString())))


Page number
Simple page count, easy to do but handy to have a copy of it around. I usually put this and the global execute time in the footer of the report:
="Page " & Globals!PageNumber & " of " & Globals!TotalPages


Global Execution time
Good for displaying in the footer in case it gets printed - the person looking at the report then knows when the report was ran.
=Globals!ExecutionTime


Clean URL for a direct link to a report
If want to provide a direct link to a report most people usually end up copying it from the Address bar in their web browser. However, that address usually has a lot of extra characters such as %20. I've found an address that can provide a somewhat cleaner link. Use the example below (substitute your own servername and Report+Name.

Example of a easy to paste direct link to a report (notice no %20, etc).
http://servername/ReportServer/Pages/ReportViewer.aspx?/Reports/Report+Name


These are pretty simple examples, but I can't remember how many times I've thanked myself for keeping them around in a small text file.