Using sp_configure with CASE statement

时间:2016-03-14 22:20:53

标签: sql-server tsql

I need to toggle sp_configure.

What I do is:

SELECT CAST(
        CASE
            WHEN value_in_use = 0
                THEN sp_configure 'clr enabled', 1
            ELSE sp_configure 'clr enabled', 0
        END AS bit)
    FROM sys.configurations 
    WHERE name = 'clr enabled'
RECONFIGURE;

But it doesn't work.

How to write a toggling sp_configure 'param' in T-SQL

What's wrong with this code?

1 个答案:

答案 0 :(得分:3)

CASE是一个表达式,用于返回不更新内容的值。

你需要像这样使用IF-ELSE

IF @Expression THEN 
    sp_configure 'clr enabled', 1
ELSE 
   sp_configure 'clr enabled', 0;