Tuesday, February 7, 2012

Store Query as Template Or Control in SSMS ToolBox

Hope many people are aware of this feature, but I came to know about it on today while watching one of the SQL Server webcast. I just want to share the same in this blog. it will be helpful to new comers.
I used to store the query in a script file for future/reference/reusable purpose, Instead of keeping as separate file, you can store the Query in SSMS Toolbox window, which will act as a Template or control.
Following steps will help you to store a Query in Toolbox:-
1.       Open SQL Server Management Studio, connect to Database server
2.       Check whether Toolbox window is opened or not, if it is not opened then go to View Menu, select Toolbox Menu,  or else open the menu using shortcut keyword (Ctrl + Alt + X)
3.       If you see any control on toolbox, then you can skip the steps 4,5 and 6
4.       When I opened the Toolbox window, it is Empty container as shown below

5.       Right Click on Toolbox, select “Show All” Options

6.       Toolbox is appeared with list of SSIS and DB Maintenance controls as shown below

7.       Open Query Window; write Some Query/Query Template whichever you want to store it. Select the Query, Drag and drop on Toolbox, Or… else copy the query, Right click and paste on the Toolbox.
Look at the following screen, I have a written a Query on Query window, then dropped the same at Toolbox as well.

8.       You can categorize the collection Queries by using Creating Tab in the toolbox. Right Click on the toolbox, select “Add Tab”, Enter the Group Name of the Queries.

9.       To reuse the Query, right click on the Query, select copy; paste the same on Query window for use.

Note: In Toolbox, if the saved Query is Enabled Mode, then you can drag the Query Template and drop into query window like placing control on designer. By default it is disabled mode. So you need to follow as step 9 to use.

No comments:

Post a Comment