# T-SQL sql server 2008 2005 中的 ifdef 类型条件编译

Gul*_*llu 4 t-sql sql-server sql-server-2005 sql-server-2008

为了向后兼容,我需要在 sql server 2005 和 sql server 2008 上运行一个存储过程。但是,由于 sql server 2008 中不推荐使用某些命令,我​​的脚本在 2005 年编译,但在 2008 年失败。我正在寻找 c++ ,c# 相当于 #define、#ifdef,这样我就可以在 2005 年和 2008 年编译相同的脚本。这方面的标准做法是什么?附上截图,详细解释。谢谢

在此输入图像描述

And*_*mar 5

使用动态SQL:

if (@returnVal = 1)
    exec ('backup log myDB with truncate_only');
Run Code Online (Sandbox Code Playgroud)