Sql Query Analyzer Template Parameters

I’m not sure if this is common knowledge, but you can place template parameters in your SQL scripts and evaluate them within query analyzer. I think I learned this one a long time ago from a former fantastic SysAdmin, turned DBA, turned Developer, Tyler.

Here’s an example of a short script that makes use of a template variable.

SELECT * FROM <tableName, varchar(32), 'MyTable'>

Paste that into SQL Query Analyzer and hit CTRL+SHIFT+M. A dialog to replace the template parameters will pop up like so

Replace Template Parameters Dialog

Just fill in the values and hit return and you’re ready to run the script.

The format for a template parameter is <parameterName, sql data type, default value>.

Technorati Tags: ,

What others have said

Requesting Gravatar... you've been HAACKED Nov 04, 2007 9:53 AM
# A Library For Executing SQL Scripts With GO Separators and Template Parameters
A Library For Executing SQL Scripts With GO Separators and Template Parameters
Requesting Gravatar... valer Nov 10, 2008 10:37 PM
# re: Sql Query Analyzer Template Parameters
How to display default value for datetime value (lets say i wnat to display current date : getdate()). It always display getdate(), without calculte the current date. Tnx.

What do you have to say?

(will show your gravatar)
Please add 3 and 2 and type the answer here: