Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

What exactly are you trying to do? It seems like you're taking a procedural-based approach when this can be done set-based.
–
Thomas StringerDec 4 '12 at 14:04

1

This type of thing can be done using a cursor (assuming you want to loop through the values)... Can you give us some context to this question? Using cursors is normally a last resort.
–
Jon SeigelDec 4 '12 at 14:15

1

Do what in a set based manner? Please provide example data and desired results.
–
Martin SmithDec 5 '12 at 8:42

@Qrosh - You want to assign the value column for each row in the table to a different variable? Does the table have a fixed number of rows? Also what do you then plan to do with the variables?
–
Martin SmithDec 5 '12 at 9:07

the number of rows Not fixed. The content of the row is unknown I posed the question a little more clearly better Please wait
–
Masoud AfrashtehDec 5 '12 at 9:23

Based on the context from your previous question SQL query for combinations without repitition I think you are looking for a way to find combinations of users and include both the name and ID in the result set. The following script demonstrates one way to achieve that:

Use the fact that the natural integers have a pattern of bits that match the combinations we want to find. Determine the maximum integer value we need based on the number of items in the working table:

Can you be more specific in what your trying to accomplish? Thomas is right, it does seem like you want to take a procedural approach to something that can be done in a set based manner.

If your looking to get a set of results and then process them one at a time for an application, I strongly recommend doing that row based processing in your application. SQL Server is designed to work with sets and not rows.

If your looking to have a procedure that returns the next row each time it is called. Again, I would suggest pulling the result set as a whole and processing the row based operations in your application code.

If you must do this in t-sql, then a cursor is what you would need. I strongly recommend against this however since a cursor is a row by agonizing row operation and cursors are not very performant.