Temporal table mode for multiple record traversal
Declare @oper_cart_item_id bigint; Declare @oper_cart_id bigint; Declare @the_last_changed_date datetime; Declare @oper_cust_id int; Select *,0 asFlag into#shoppingcart_temp fromdeleted; while exists(Select Top 1 1 from#shoppingcart_temp TwhereT.flag= 0 ) begin Select Top 1 @oper_cart_item_id =CART_ITEM_ID,@oper_cart_id =cart_id,@oper_cust_id =cust_id,@the_last_changed_date =last_changed_date from#shoppingcart_tempwhereFlag= 0 ; if @oper_cart_item_id is not NULL and @oper_cart_item_id <> 0 and Left(@oper_cart_id,1)= '8' begin execProc_sqlser_insertqueue@oper_cart_id,@oper_cart_item_id,@the_last_changed_date,@oper_cust_id,'3'; End Update#shoppingcart_tempSetFlag= 1 wherecart_item_id= @oper_cart_item_id End
Cursors for multiple record traversal
Declare @oper_cart_item_id bigint; Declare @oper_cart_id bigint; Declare @the_last_changed_date datetime; Declare @oper_cust_id int; DeclareShoppingcart_cursorcursor for SelectCart_item_id,cart_id,cust_id,last_changed_date fromdeleted; OpenShoppingcart_cursorFetch Next fromShoppingcart_cursor into @oper_cart_item_id,@oper_cart_id,@oper_cust_id,@the_last_changed_date while(@ @fetch_status=0) begin if @oper_cart_item_id is not NULL and @oper_cart_item_id <> 0 and Left(@oper_cart_id,1)= '8' begin execProc_sqlser_insertqueue@oper_cart_id,@oper_cart_item_id,@the_last_changed_date,@oper_cust_id,'3'; End Fetch Next fromShoppingcart_cursor into @oper_cart_item_id,@oper_cart_id,@oper_cust_id,@the_last_changed_date End CloseShoppingcart_cursordeallocateShoppingcart_cursor