SQL Server cursor simple application (grouping minimum)

Source: Internet
Author: User
Previously, http://www.cnblogs.com/raymond19840709/archive/2008/02/26/1082377.html also mentioned the related problem solution, but not suitable for solving the following such problems, now provides a more general and easy-to-understand Method
The following data:
1 copy of Land Use Certificate
2. Copies of the land use certificate
3. Copies of the land use certificate
4. Copies of the land use certificate
5. Copies of the land use certificate
6. Copies of the land use certificate
7. Copies of the land use certificate
8. Copies of the land use certificate
9 copy of Land Use Certificate
10 copies of land use certificate
11 copy of Land Use Certificate
12 copy of Land Use Certificate
13 copy of Land Use Certificate
14 copies of land use certificate
15 copies of land use certificate
16 completion acceptance Filing Form
17 Completion Acceptance Filing Form
18 completion acceptance Filing Form
19 completion acceptance Filing Form
20 completion acceptance Filing Form
21 acceptance notice and completion plan acceptance certificate
22 Construction Area Measurement statement or real estate measurement report
23 Construction Area Measurement statement or real estate measurement report
24 Construction Area Measurement statement or real estate measurement report
25 Construction Area Measurement statement or real estate measurement report
26. Proof of Public Security house board arrangement, proof of application, and book settlement
27. Proof of Public Security house board arrangement, proof of application, and book settlement
28. Proof of Public Security house board arrangement, proof of application, and book settlement
29. Proof of Public Security house board arrangement, proof of application, and book settlement
30. Proof of Public Security house board arrangement, proof of application, and book settlement
31. Proof of establishment of Public Security house Cards, proof of application, and book settlement
32 books written
33 books written
34. Ownership ID card copy or legal representative ID card
35. A copy of the owner's ID card or the ID card of the legal representative
36 transaction application and receipt
37 Real Estate Right Registration
38 Real Estate Right Registration
39 Real Estate Right Registration Receipt and real estate right certificate stub
40 Real Estate Right Registration Receipt and real estate right certificate stub
41 copies of land use certificates and real estate ownership certificates
42 copies of land use certificates and real estate ownership certificates
43 copies of land use certificates and real estate ownership certificates
44 mortgage contract, list, supplementary agreement
45. Mortgage Contract, list, and supplementary agreement
46 mortgage contract, list, supplementary agreement
47 mortgage contract, list, supplementary agreement
48 mortgage contract, list, supplementary agreement
49 mortgage contract, list, supplementary agreement
50 mortgage contract, list, supplementary agreement
51 mortgage contract, list, supplementary agreement
52 copy of Bank power of attorney and Agent ID card
53 copy of bank letter of authorization and Agent ID card
54 copy of bank letter of authorization and Agent ID card
55 copy of bank letter of attorney and Agent ID card
56 Property Rights inventory
57 business license or legal person Code Copies of certificates and legal person certificates
58 business license, legal person code certificate, legal person certificate Copy
59 business license, legal person code certificate, legal person certificate Copy
60 business license, legal person code certificate, legal person certificate Copy
61 business license, legal person code certificate, legal person certificate Copy
62. Business license, legal person code certificate, and Legal Person Certificate
63 copies of land use certificate
64. A copy of the owner's ID card or the ID card of the legal representative
65. Ownership ID card copy or legal representative ID card
66 his transaction application and receipt
67 real estate other ownership registration
68 real estate other ownership registration
69 real estate other ownership credential stubs
70 real estate other rights and interests certificate stubs
71 real estate other ownership credential stubs

Obtained :(Note: duplicate copies of the "Land Use Certificate" are displayed, so the problem cannot be solved using Min.)
1 copy of Land Use Certificate
16 completion acceptance Filing Form
21 acceptance notice and completion plan acceptance certificate
22 Construction Area Measurement statement or real estate measurement report
26. Proof of Public Security house board arrangement, proof of application, and book settlement
32 books written
34. Ownership ID card copy or legal representative ID card
36 transaction application and receipt
37 Real Estate Right Registration
39 Real Estate Right Registration Receipt and real estate right certificate stub
41 copies of land use certificates and real estate ownership certificates
44 mortgage contract, list, supplementary agreement
52 copy of Bank power of attorney and Agent ID card
56 Property Rights inventory
57 business license, legal person code certificate, legal person certificate Copy
63 copies of land use certificate
64. A copy of the owner's ID card or the ID card of the legal representative
66 his transaction application and receipt
67 real estate other ownership registration
69 real estate other ownership credential stubs

Code:

Create procedure raytest
Create Table # temp (TNO int, tType varchar (50 ))
Declare @ temp_current varchar (50)
Declare @ temp_before varchar (50)
Declare @ temp_no int
Declare mycursor cursor for select imageno, imagetype
From imageproperty_t
Order by imageno ASC
Open mycursor

Fetch next from mycursor
Into @ temp_no, @ temp_current
Set @ temp_before = @ temp_current
Insert into # temp (TNO, tType)
Values (@ temp_no, @ temp_current)

While (@ fetch_status = 0)
Begin
If @ temp_current <> @ temp_before
Begin
Insert into # temp (TNO, tType)
Values (@ temp_no, @ temp_current)
End
 
Set @ temp_before = @ temp_current
Fetch next from mycursor
Into @ temp_no, @ temp_current
End
Close mycursor
Deallocate mycursor

Select imageno, imagetype
From imageproperty_t
Order by imageno ASC
Select * from # temp
Go

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.