tags:

views:

305

answers:

2

Hi,

I have a select statement and a cursor to iterate the rows I get. the problem is that I have many columns (more than 500), and so "fetch .. into @variable" is impossible for me. how can I iterate the columns (one by one, I need to process the data)?

Thanks in advance, n.b

+1  A: 

Two choices.

1/ Use SSIS or ADO.Net to pour through your dataset row by row. 2/ Consider what you're actually needing to achieve and find a set-based approach.

My preference is for option 2. Let us know what you need done and we'll find a way.

Rob

Rob Farley
That what I did .. I have one table which get the data from a flat file using SSIS. now I need to process the data (validation, matching etc.) and iterating the columns seems necessary for it.n.b
nab, you never need to iterate to do validation or matching. In fact you almost never need to iterate to do anything. I fyou are using a cursor, that is your first clue to look for a better way to do things. I import data all the time and do all data cleanup with set-based code which is usually much faster than iteration. Or you can do all the data validation in your SSIS package.
HLGEM
nab - you'd've been better off putting the validation in the SSIS package. Then you can send the unvalidated data off to a different table, or through a set of cleansing processes, while the clean data ends up in your table. Rob
Rob Farley
A: 

You can build a SQL string using sys.columns or INFORMATION_SCHEMA queries. Here's a post I wrote on that.

Jon Galloway