For example:
exec SP_ChangeNameOfTable tbl1_data_20200124
SELECT *
INTO #TEMP_DATA
FROM [LOADED].DBO.tbl1_data_20200123
WHERE [Owner] IS NULL
I want to change this table name from 20200123
to 20200124
using a stored procedure.
For example:
exec SP_ChangeNameOfTable tbl1_data_20200124
SELECT *
INTO #TEMP_DATA
FROM [LOADED].DBO.tbl1_data_20200123
WHERE [Owner] IS NULL
I want to change this table name from 20200123
to 20200124
using a stored procedure.
you need to use dynamic sql while trying to pass dynamic table name in SP.
something like,
create procedure SP_ChangeNameOfTable
(
@table_name as varchar(200)
)
As
begin
declare @sc as varchar(max)='SELECT * into #TEMP_DATA FROM
[LOADED].[dbo].'+@table_name+' where [Owner] is null'
execute(@sc);
end
Call the SP as you like,
exec SP_ChangeNameOfTable 'tbl1_data_20200124'