Looping through a result set in a SQL Server stored procedure
I have a stored procedure in which I want to dynamically build a query string or order by clause and execute it. The column names I want to select are stored in a table. So in my stored procedure I wanted to do something like:
1. Do a query against this lookup table and get a list of column names
2. Loop through that list and build an order by clause.
3. Append the order by clause to a select query, execute it, and return the result set.
I am not sure how to do this though. In Oracle there was this cursor that allowed me to loop through the results of a select statement, but I can't figure out how to do it here and also not to return that result set. Thanks.
Microsoft SQL Server 2005
Guy Hengel [angelIII / a3]
8/22/2022 - Mon
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat