title: T-SQL Cursors alternate in BigQuery
body: <p>I have a stored procedure written in T-SQL which uses cursors but now I want to use it in Google BigQuery. I am re-writing the query in GBQ but don't know how to convert cursor logic because bigquery doesn't support it. Below is the T-SQL script which I want to convert into BigQuery:</p>
  
  <pre><code>DECLARE
      @query              cursor,
      @wm_query           cursor,
  
      @passenger_id       varchar(48),
      @trip_no            nvarchar(255),
      @created_at         datetime2(7) ,
      @prev_cash_balance  numeric(18,5),
      @prev_promo_balance numeric(18,5),
      @_id                nvarchar(255)
  
  SET @query = CURSOR FAST_FORWARD FOR
      SELECT passenger_id, trip_no, created_at, _id
      FROM source_wallet
      ORDER BY passenger_id, created_at, _id
  
  OPEN @query
  FETCH NEXT FROM @query INTO @passenger_id, @trip_no, @created_at, @_id
  
      WHILE @@FETCH_STATUS = 0
      BEGIN
          SET @wm_query = CURSOR FAST_FORWARD FOR
          select top 1 cash_balance, promo_balance from wallet_master where passenger_id = @passenger_id 
          order by created_at desc, _id desc
  
              OPEN @wm_query
              FETCH NEXT FROM @wm_query into @prev_cash_balance, @prev_promo_balance
  
                  insert into wallet_master (passenger_id, created_at, cash_usage, promo_usage, _id)
                  select @passenger_id, @created_at, case&lt;some logic&gt;, case&lt;some logic&gt;, _id
  
              CLOSE @wm_query
              deallocate @wm_query
          FETCH NEXT FROM @query into @passenger_id, @trip_no, @created_at, @_id          
      END
  CLOSE @query
  DEALLOCATE @query
  </code></pre>