954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Sybase passing variable column names

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 :)

voidyman
Newbie Poster
17 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

You have to frame the SQL at run time and execute the same using as dynamic SQL in a stored procedure.

Read more here and here .

debasisdas
Posting Genius
6,872 posts since Feb 2007
Reputation Points: 666
Solved Threads: 434
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: