SQL Server script multiple record traversal

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.