cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic select inside storedprocedure

Former Member
0 Kudos

Hi All,

I have a requirement to generate the dynamic select statement . Procedure will accept the table name and schema name as parameters and return the select statement.

I could able to get the column names from sys.columns table. How to loop through the rows and concatenate the column values into single string?

Regards,

Suman.

Accepted Solutions (1)

Accepted Solutions (1)

former_member182302
Active Contributor
0 Kudos

Hi Suman,

Have a look on the below document:

Regards,

Krishna Tangudu

Former Member
0 Kudos

Thank you Krishna!!

That Document was really helpful.

Regards,

Suman.

Answers (2)

Answers (2)

justin_molenaur2
Contributor
0 Kudos

Hi there, take a look a the syntax for the procedure shown in , this should help you along with a similar requirement.

Regards,

Justin

former_member182302
Active Contributor
0 Kudos

Hi Suman,

I guess you are working on replicating procedure, if am not wrong.

You can use a cursor to achieve it. You can open a cursor to read the columns even from a table TABLE_COLUMNS and then loop and concatenate them into a single string to form you insert or update query.

Regards,

Krishna Tangudu