2

I have a database project in Visual Studio 2008, and I want the ability to run a preprocessor on my sql code (using it to allow for variable database names without resorting to dynamic sql). So I'd like to change what action occurs when I hit the run button to include running the code through the preprocessor automatically.

Is there a way to do this? I looked through the dbp file, and there don't seem to be any options even close to this.

1 Answer 1

3

One option is to use SQLCMD Mode in your database project scripts.
(VS Menu: Data -> TSQL Editor -> SQLCMD Mode).

In your scripts you can define variables that get replaced when you run them. Example:

:SETVAR tablevar Customers GO SELECT * FROM $(tablevar) /* translates to SELECT * FROM Customers */ 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.