# ifdef type conditional compilation in T-SQL sql

2019-07-19 02:31发布

For sake of backwards compatibility I need to have a stored proc run on both sql server 2005 AND sql server 2008. However due to some commands being deprecated in sql server 2008 my script compiles on 2005 but fails on 2008. I am looking for the c++, c# equivalent of #define, #ifdef so I can compile the same script on 2005 & 2008. What is the standard practice on this ? Attached screenshot explains in detail. thank you

enter image description here

1条回答
欢心
2楼-- · 2019-07-19 02:52

Use dynamic SQL:

if (@returnVal = 1)
    exec ('backup log myDB with truncate_only');
查看更多
登录 后发表回答