2013-02-14 49 views

回答

0

使用SET @local_variable

SET { { @local_variable = expression } 
    | { @cursor_variable = { @cursor_variable | cursor_name 
      | { CURSOR [ FORWARD_ONLY | SCROLL ] 
       [ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ] 
       [ READ_ONLY | SCROLL_LOCKS | OPTIMISTIC ] 
       [ TYPE_WARNING ] 
      FOR select_statement 
       [ FOR { READ ONLY | UPDATE [ OF column_name [ ,...n ] ] } 
       ] 
      } 
    } } 
} 
0

使用包含SQL作爲查詢的一部分,你需要的EXECUTE語句的字符串。

DECLARE @Condition NVARCHAR(50) = 'AND user_name IN (''deep'')'; 

EXECUTE('SELECT * FROM table WHERE id = 10 ' + @Condition); 
相關問題