Custom SQL function numbers include metric indicators

Source: Internet
Author: User

 

1 -- input a string parameter and return a string
2 create function pmselect (@ pproid nvarchar (40 ))
3 returns nvarchar (50)
4 begin
5 declare @ plist nvarchar (50)
6 declare @ PM nvarchar (10)
7 -- Define a cursor
8 declare pm_cursor cursor
9 select personname from tblperson where oId in (select user_id from tblpromanager where pro_id = @ pproid)
10
11 -- open the cursor and save the retrieved content to @ pm
12 open pm_cursor
13 fetch next from pm_cursor into @ pm
14 set @ plist =''
15
16 -- loop if data exists
17 while @ fetch_status = 0
18 begin
19 if (@ plist = '')
20 set @ plist = @ pm
21 else
22 set @ plist = @ plist + ',' + @ pm
23 fetch next from pm_cursor into @ pm
24
25 end
26
27 -- close the cursor
28 close pm_cursor
29 deallocate pm_cursor
30
31 -- return results
32 return @ plist
33
34
35 end
36
37

 

 

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.