The question indicates that you are mixing data with metadata. Table
names shouldn't carry information in an ideal database. If a redesign
is impossible, is it possible to put the data where it belongs, in a
column (of a view)?
create view Better as
select
'ThisTable' as someData,
columnA,
columnB, ...
from ThisTable
union all
select
'ThatTable',
columnA,
columnB, ...
....
go
Then the sp can be written as
select ...
from Better
where someData = @tableName
Steve Kass
Drew University
[quoted text, click to view] exBK wrote:
>Hi,
>In a SP, I want to switch table names based on an input parameter. I am afraid of dynamically building the entire SQL because of SQL Injection problems. Any suggestions on how to achieve this ?
>
>
>
>
>