The best answer is SQLMenace as required if necessary to create a time constant for use in scripts, i.e. for multiple GO statements / packages.
Just create a procedure in tempdb, then you will not affect the target database.
One practical example of this is to create a script database that writes a control value at the end of a script containing a version of the logic diagram. At the top of the file are some comments with a change history, etc. But in practice, most developers will forget to scroll down and update the version of the circuit at the bottom of the file.
Using the above code allows you to determine the constant of the visible version of the diagram at the top before the script database (copied from the SSMS script generation function) creates the database, but is used at the end. This is right in front of the developer along with the change history and other comments, so they are likely to update it.
For example:
use tempdb go create function dbo.MySchemaVersion() returns int as begin return 123 end go use master go
Tony Wall Dec 03 '12 at 14:56 2012-12-03 14:56
source share