Stored Procedure example (1)

Source: Internet
Author: User
Tags stored procedure example

For example, the stored procedure starts from a node N and finds the parent node at the top. This frequently used process can be undertaken by the stored procedure and shared by repeated use on the webpage.

Null: indicates that the node is a top-level node.

Fjdid (parent node number)

Node N is not empty. It indicates the parent node number of the node.

Dwmc (unit name)

Create proc search_dwmc @ dwikidold int, @ dwmcresult varchar (100) Output
As
Declare @ stop int
Declare @ result varchar (80)
Declare @ dwmc varchar (80)
Declare @ dwid int
Set nocount on
Set @ stop = 1
Set @ dwmc = ""
Select @ dwmc = dwmc, @ dwid = convert (INT, fjdid) from jtdw where id = @ dwidold
Set @ result = rtrim (@ dwmc)
If @ dwid = 0
Set @ stop = 0
While (@ stop = 1) and (@ dwid <> 0)
Begin
Set @ dwidold = @ dwid
Select @ dwmc = dwmc, @ dwid = convert (INT, fjdid) from jtdw where id = @ dwidold
If @ rowcount = 0
Set @ dwmc = ""
Else
Set @ result = @ dwmc + @ result
If (@ dwid = 0) or (@ rowcount = 0)
Set @ stop = 0
Else
Continue
End
Set @ dwmcresult = rtrim (@ result)

Use exec pro-name [pram1 pram2....]
 

(Www.gz u521.com), original address: http://www.gzu521.com/campus/article/program/200803/165794.htm

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.