I'm running a simple insert/select query that requires a change in table names each time it is run. I want to set it up as a stored procedure using input parameters for the two table names that change, but am not sure if SQL accepts paramaters in place of table names. The code so far is:
create procedure sp_DataProv
as
insert into tblDataProvPartNum
(
mc,
nsc,
nc,
iin,
partnum,
cttcode,
smb,
smbsub
)
select
a.mc,
a.nsc,
a.nc,
a.iin,
a.partnum,
a.cttcode,
b.smb,
b.smbsub
from tblPartNum a left join tblCostUse b on
a.mc=b.mc and a.nc=b.nc and a.iin=b.iin
Any help on how to replace the 2 table names in the select statement would be much appreciated.
create procedure sp_DataProv
as
insert into tblDataProvPartNum
(
mc,
nsc,
nc,
iin,
partnum,
cttcode,
smb,
smbsub
)
select
a.mc,
a.nsc,
a.nc,
a.iin,
a.partnum,
a.cttcode,
b.smb,
b.smbsub
from tblPartNum a left join tblCostUse b on
a.mc=b.mc and a.nc=b.nc and a.iin=b.iin
Any help on how to replace the 2 table names in the select statement would be much appreciated.