Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
SQL Server 2008 126
SQL Server 2005 109
TSQL Tips n Tricks 80
Performance Tuning 57
SQL Server 2012 48
SQL Server Basics 24
Sql Server Management 21
SSMS 21
Index 18
SQL Server Denali 13

Archive · View All
March 2011 24
December 2010 23
January 2011 22
May 2011 17
February 2011 16
April 2011 16
July 2012 12
August 2011 9
September 2012 8
August 2012 8

SQL Server: Query Template, a Time Saving Feature

May 18 2011 11:40PM by aasim abdullah   

While working with SQL Server, its common to have a saved script which you need to execute for different server or databases and usually you open this saved script, make changes according to requirements and execute. SQL Server 2008 has one more time-saving facility. You can save your script as template, like following is a simple query script, which I like to execute for different databases and with different order by clause.

USE AdventureWorks
GO
SELECT s.SalesPersonID, c.Title, c.FirstName,c.MiddleName, c.LastName, c.Suffix,e.Title AS JobTitle,s.SalesQuota, s.SalesYTD
FROM Sales.SalesPerson AS s INNER JOIN HumanResources.Employee AS e ON e.EmployeeID = s.SalesPersonID LEFT OUTER JOIN Sales.SalesTerritory AS st ON st.TerritoryID = s.TerritoryID INNER JOIN Person.Contact AS c ON c.ContactID = e.ContactID 
ORDER BY c.FirstName

One solution to avoid any labor work to change above script manually according to my requirements, is to create a dynamic query. But, in SQL Server 2008 I would prefer Query Template, by saving above query in following Template.

USE <UseDatabase,,AdventureWorks>

GO
SELECT s.SalesPersonID, c.Title, c.FirstName, c.MiddleName, c.LastName,c.Suffix,e.Title AS JobTitle,s.SalesQuota, s.SalesYTD
FROM Sales.SalesPerson AS s INNER JOIN HumanResources.Employee AS e ON e.EmployeeID = s.SalesPersonID LEFT OUTER JOIN Sales.SalesTerritory AS st ON st.TerritoryID = s.TerritoryID
INNER JOIN Person.Contact AS c ON c.ContactID = e.ContactID
ORDER BY <OrderByColumn,,c.FirstName>

Next time when I need to execute this script, I will just open the template and press Ctlr+Shift+M or click on replace button Replace , and it will ask me  for template parameters value and on pressing OK button it will replace template parameters with my values on whole script.

Defining a template needs three parameters separated with comma and enclosed with < and > signs.

<TemplateParameter, ParameterDataType, DefaultValue>

 

Tags: SQL Server 2008, SQL Server Basics, Tricks, brh, TSQL Tips &amp;amp, amp,


aasim abdullah
23 · 7% · 2373
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

2  Comments  

  • a Wowww tips :) I used to store my queries in a file called query.txt for further uses , this seems to me a nice alternative , thank you.

    Javin
    10 tips on using find command in Unix

    commented on May 20 2011 3:15PM
    Javin Paul
    2388 · 0% · 5

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]