build dynamic sql and then use exec or sp_executesql to run query
EXEC | EXECUTE
Example
DECLARE @table VARCHAR(50) = 'HR.Employees'; EXEC ( 'SELECT * FROM '+@table );
Example 2 [Stored Procedure]
DECLARE @ID INT = 34; EXEC ( '[dbo].[p__Clean] '''+@ID+'''' );
No comments:
Post a Comment