Short version: Is there some way to conditionally compile chunks of TSQL code in a SQL Server Data Project using SQL Server Data Tools for Visual Studio 2010?
I'm using SQL Server Data Tools in Visual Studio 2010 to work on an experimental SQL Server Express database. The eventual destination if things work well would be an enterprise SQL Server platform. I have both a 2008 instance on one box and a 2012 instance on another, because my company is in the process of migrating from 2008 to 2012 for the many enterprise databases as well.
In other programming languages I have used, preprocessor directives make it easy to conditionally compile parts of a code base. The most common uses for this are to have different code for different platforms in restricted sections or to excluded debugging output code from release builds.
Both of these could be very helpful in some store procedures I'm working on. Is there anything like this available? I know I can use
sqlcmd variables to swap out specific values during deployment, but I can't figure how to use that to include or exclude subsequent chunks of code.
#IF $(DebugVersion) = 'True' -- A bunch of useful PRINTs and what not #ELSE SET NOCOUNT ON #ENDIF #IF $(SSVersion) = '2012' SET @pretty_date = FORMAT(@some_date, 'dddd, MMM dd, yyyy') #ELSE SET @pretty_date = CAST(@some_date AS nvarchar(12)) #ENDIF