我有一些代码,例如:
declare @Condition nvarchar(50), --value 'and user_name in ('deep')
select * from table where id = 10
之后10
我想放@Condition
价值。如何分配和放置?
我有一些代码,例如:
declare @Condition nvarchar(50), --value 'and user_name in ('deep')
select * from table where id = 10
之后10
我想放@Condition
价值。如何分配和放置?
要将包含 SQL 的字符串用作查询的一部分,您需要该EXECUTE
语句。
DECLARE @Condition NVARCHAR(50) = 'AND user_name IN (''deep'')';
EXECUTE( 'SELECT * FROM table WHERE id = 10 ' + @Condition );
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 ] ] }
]
}
} }
}