-1

我有一些代码,例如:

declare @Condition nvarchar(50), --value  'and user_name in ('deep') 
select * from table where id = 10 

之后10我想放@Condition价值。如何分配和放置?

4

2 回答 2

0

要将包含 SQL 的字符串用作查询的一部分,您需要该EXECUTE语句。

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

EXECUTE( 'SELECT * FROM table WHERE id = 10 ' + @Condition );
于 2013-02-17T06:02:54.143 回答
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 ] ] } 
                ] 
            } 
    } } 
}
于 2013-02-14T10:26:04.793 回答