tsql - How to make table dynamic in sql -
Does anybody know how to run a table based on the variable is to write the script in the stored proc (or it is possible Hence?)? For example: I have names of 3 tables named Customer, Supplier, and Support
When user input 1, then table customer, 2 table supplier and 3 support table support
< Input code> input input; If @input = 1 declares, then @Tale Vivarkar (50); Set @table = 'Client' end if declared @input = 2, then 'Taylor Wirt (50); Set @table = 'Supplier' end if @input = 3 is declared, table workers (50); Set @table = 'support' and select * INTO ## test from @table
< P> Yes, you can do this by using the dynamic SQL "EXEC" or "Sp_Executesql" command. Example:
Use Northwind make table #MyTemp (RowID int IDENTITY, LastName varchar (20)) DECLARE @SQL nvarchar (250) SET @sQL = '# Include in the Employee Choose the last name from the employee; ' Execute SP_executesql @SQL
Comments
Post a Comment