sql - Iterate temp table in batches -


i have temp table set of data

----------------------------------------------------- | col1  | col2      | col3      | col4      | status|  ----------------------------------------------------- |     | a12       | dd        | ff        | 1     |  ----------------------------------------------------- | b     | b43       | dd        | ff        | 2     |  ----------------------------------------------------- | c     | fe3       | dd        | ff        | 3     | ----------------------------------------------------- | d     | fd2       | gg        | hh        | 1     |    -----------------------------------------------------                | e     | sf2       | gg        | hh        | 1     |    -----------------------------------------------------    | f     | vd2       | ii        | jj        | 3     | ----------------------------------------------------- | g     | cd3       | ii        | jj        | 3     | ----------------------------------------------------- 

i need process table in batches select of rows.

i.e

first consider rows col3 =dd , col4=ff , select 1 row (i have algorithm select row) consider rows col3=gg , col4=hh , select onse consider rows col3=ii , col4=jj , select 1 row.

how can iterate through temp table select subset of row , process .??

i need 1 row each subset (subset same col3 , col4) based on status column.

expected result:-


| col1  | col2      | col3      | col4      | status|  ----------------------------------------------------- | b     | b43       | dd        | ff        | 2     |  -----------------------------------------------------     | d     | fd2       | gg        | hh        | 1     |    -----------------------------------------------------                | f     | vd2       | ii        | jj        | 3     | ----------------------------------------------------- 

it depends on purpose , database engine.

  1. if want iterate , modify data in table can use cursor, while loop, cte, recursive update...
  2. if want iterate objects (tables, databases) should use sytem foreach based procedure (for example sp_msforeachdb).
  3. if want value , select next table should use function.
  4. if want iterative solution can use cursor or while loop. try rethink plan , try use set-based solution (of course, if it's possible).

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -