How to dynamically pass values to SQL ?


How to dynamically pass values to SQL ?


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


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.
Junior Contributor

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