I have 15 stored procedures that return data from a common table and then join that table with a specific table to retrieve inventory.
Example:
Commo
Yep, you can generate an SQL statement dynamically and then execute it.
For example,
DECLARE @specificTableName nvarchar(50)
DECLARE @specificColumnName nvarchar(50)
SET @specificTableName = 'tblSpecific'
SET @specificColumnName = 'colSpecific'
DECLARE @sql nvarchar(4000)
set @sql = 'SELECT ... FROM tblCommon c INNER JOIN ' +
@specificTableName + ' s ON c.PrimaryKey = s.' + @specificColumnName
exec (@sql)