How to dynamically pass values to SQL ?

Database

How to dynamically pass values to SQL ?

Hi,

I have a requirement to analyse the each of the column values for a group of tables...table name will be a parameter value.
I am not suppose to write a Store procedure.
Is there any other alternative way to achieve iteration or looping of executing the same sql with changing table name and column name values with temp tables etc

Thanks.
2 REPLIES
WAQ
Enthusiast

Re: How to dynamically pass values to SQL ?

The immediate solution that comes to my mind is that you can create a Macro having one parameter, tableName. That macro will return the complete SQL for that particular table, which then you need to execute.

But keep in mind that you CAN NOT loop in macro. You need to exec that macro, everytime you requrie the SQL for any specifc table.

Probably some more explanation will help to provide a better solution.
Senior Apprentice

Re: How to dynamically pass values to SQL ?

If you're supposed not to write an SP, you should tell your boss/dba, that this is foolish.

Of course you can write some BTEQ scripts to create and run the neccessary SQL, too, but this is more complicated than an SP.

Don't use a hammer if you have to tighten a screw :-)

Dieter