SQL Server Stored Procedures

Source: Internet
Author: User

1 CREATE PROCEDURE Delete_date2 (3 @applycode nvarchar4 )5  as6--declaring variable definition variables separated by commas7declare @applycode_var nvarchar ( -),8@instanceid_var nvarchar ( -),9@t_ywsloid_var nvarchar ( -),Ten@areaPart_oid nvarchar ( -), One@areaPartoid nvarchar ( -) A begin ---Identify workflow Instances -   Select@instanceid_var =instanceid fromT_ywslwhereApplycode=@applycode the--Delete a task table for a workflow instance (Todo and done) -Delete fromAssigntaskwhereAssigntask.instanceid=@instanceid_var - Commit ---Query Business Handling OID +   Select@t_ywsloid_var =t_ywsloid fromT_ywslwhereApplycode=@applycode -  +--loop to delete the corresponding coordinate range A--SQL Server at--Defining Cursors - DECLARE my_cursor cursor ---reading data into the cursor -    for(SelectAreapartoid fromAreapartwhereT_ywsloid=@t_ywsloid_var) ---Open Cursor - Open My_cursor in--reads the first row of data in the collection -FETCH NEXT frommy_cursor into @areaPart_oid to--global variable, 0 means the fetch statement succeeds;-1 indicates that the statement failed or the row is not in the result set;2 rows that are fetched do not exist +    while@ @FETCH_STATUS =0 - begin theDelete fromAreapointswhereAreapartoid=@areaPart_oid * Commit $--Read Next linePanax NotoginsengFETCH NEXT frommy_cursor into @areaPart_oid - End the Close My_cursor + deallocate my_cursor A    the--delete the corresponding parcel list +Delete fromAreapartwhereT_ywsloid=@t_ywsloid_var - Commit $--Delete the corresponding attachment management $Delete fromFilemanagewheret_ywsl_fk=@t_ywsloid_var - Commit ---Approval Comments theDelete fromSpyjwheret_ywsl_fk=@t_ywsloid_var - CommitWuyi--Process Advice the--Workflow Instance Notebook -Delete fromFlowinstancewhereInstanceid=@instanceid_var; Wu Commit ---Active Transition Condition set AboutDECLARE t_cursor cursor for  $   SelectTaskticketoid fromTaskticketwhereInstanceid=@instanceid_var - Open T_cursor -FETCH NEXT fromt_cursor into @areaPartoid -    while@ @FETCH_STATUS =0 A begin +Delete fromTransconditionexwheretaskticket_fk=@areaPartoid the Commit -FETCH NEXT fromt_cursor into @areaPartoid $ End the Close T_cursor the deallocate t_cursor the--Task Table theDelete fromTaskticketwhereInstanceid=@instanceid_var - Commit in--Business Acceptance Form theDelete fromT_ywslwhereApplycode=@applycode the Commit AboutEnd
View Code

SQL Server Stored Procedures

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.