THE SQL Server Blog Spot on the Web

Welcome to - The SQL Server blog spot on the web Sign in | |
in Search

Adam Machanic

Adam Machanic, Boston-based SQL Server developer, shares his experiences with programming, monitoring, and performance tuning SQL Server. And the occasional battle with the query optimizer.

Introducing: TSQLMacro

I am pleased to announce the official introduction of the TSQLMacro framework, version 0.5 (prebeta-1). This version is functionally complete based on the initial design spec, features are stable, and I am not currently aware of any bugs.

So what is TSQLMacro? You can get a complete rundown here. But in essence, TSQLMacro is my attempt to bring C/C++-style macro and preprocessor support into TSQL, in order to ease certain development burdens. Please read the TSQLMacro Introduction for a detailed analysis of those issues.

And of course, there's a download page. But I highly recommend reading up before downloading -- I haven't yet included a readme or any other kind of documentation in the download.

As always -- and especially, in this case -- I would appreciate any comments, feedback, suggestions, rants, or other things you'd like to tell me about this project! I've spent a huge amount of time -- way too much time -- working on this, so I'm eager to see what people think! Thanks!

Published Wednesday, July 12, 2006 10:37 PM by Adam Machanic

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS



Adam Machanic said:

Yes, yet another introduction (although there was almost zero reaction to yesterday's introduction ).

January 25, 2009 2:55 PM

Rajib Bahar said:




thanks for this entry... the above example is all I need to understand it's value.

October 22, 2009 11:35 AM

Bob Sather said:

Hello Adam,  I'm a developer (C++ & Sybase SQL) based at an investiment bank in London. I'm frustrated at the lack of preprocessor-like facilities in SQL. Two questions:

1) When you mention TSQL do you mean Transact-SQL as used by Sybase?

2) Does your TSQLMacro preprocessor include an #include statement? Or do you know of one that does?  I am developing interconnected stored procedures on Sybase, which may share a number of #temp tables. They will only compile if each file contains its own definition of each of the tables. If the definition of a table changes, I have to change it in all of the files. Errors are easy to make. There should be an #include statement, like in C/C++, so I only have to define a table in one place.  #include would also make it possible to define the parameter set of a stored procedure in one place.

Best regards,  

Bob Sather

November 30, 2012 12:41 PM

Adam Machanic said:

Hi Bob,

SQL Server. It -might- work on Sybase, as the T-SQL dialects are relatively similar due to a shared history, but I've never tried.

As for #include, no. That's not really a macro directive, so it would be out of scope for TSQLMacro. And honestly I'm not sure how it would be implemented. It's an interesting idea, though. Is Sybase the same as SQL Server where a #temp table created in an outer scope can be referenced in a stored procedure? (And is that what you're trying to solve for?) If so, I feel your pain, but it's not a problem I've ever devoted much energy to dealing with -- except by avoiding the situation altogether whenever possible.

November 30, 2012 4:42 PM

Leave a Comment


About Adam Machanic

Adam Machanic is a Boston-based SQL Server developer, writer, and speaker. He focuses on large-scale data warehouse performance and development, and is author of the award-winning SQL Server monitoring stored procedure, sp_WhoIsActive. Adam has written for numerous web sites and magazines, including SQLblog, Simple Talk, Search SQL Server, SQL Server Professional, CoDe, and VSJ. He has also contributed to several books on SQL Server, including "SQL Server 2008 Internals" (Microsoft Press, 2009) and "Expert SQL Server 2005 Development" (Apress, 2007). Adam regularly speaks at conferences and training events on a variety of SQL Server topics. He is a Microsoft Most Valuable Professional (MVP) for SQL Server, a Microsoft Certified IT Professional (MCITP), and an alumnus of the INETA North American Speakers Bureau.

This Blog


Privacy Statement