0

Hi,
Is there a way i can pass variable column names to a stored proc?
Here's what i want to do:
i have lots of tables and for each of those i want to select out a few columns.
e.g
from table titles i want to pick out title_name and cost
then maybe i want to go to publishers and pick out mean cost and country.
I have the table names and the column names in a perl script. Can i pass these as variables to a generic stored proc?
here's what i tried:

create procedure test_proc
@file VARCHAR(256)
@table VARCHAR(50)
as
select @file
from @table

In the above example, i will pass in titles as the @table variable and "title_name, cost" as the @file variable.
but this does not seem to work as it considers @file to be a character string(as it should).
Any work arounds for this?
Thanks :)

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by debasisdas
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.