Get the first record with the variable

Source: Internet
Author: User
Based on any previous record, we can get the donation we should make now:

Create procedure insertjzk_use
(
@ PFLAG int out, -- whether the flag has been issued
@ Pzzxq varchar (20)-funding for the semester
@ Sid varchar (20) -- Student ID
)
As
Declare @ zzje float
Declare @ ylje float
Declare @ slevel varchar (20)
If exists (select * From t_jzk_use where zzxq = @ pzzxq) -- whether this semester has been issued
Begin
Set @ PFLAG = 1
End
Else
Begin
Set @ PFLAG = 0
Select @ ylje = ylzzk from t_student where student_id = @ Sid -- find the reserved amount
If @ ylje <> 0 -- check whether the reserved amount is used up
Begin
If exists (select * From t_jzk_use where student_id = @ Sid)
Begin
Select @ zzje = Top 1 zzje from t_jzk_use where student_id = @ Sid order by student_id (top 1 is incorrect)
Insert into t_jzk_use (student_id, zzxq, zzje) values (@ Sid, @ pzzxq, @ zzje)
End
Else
Begin
Select @ slevel = school_level from t_student where student_id = @ Sid -- get the level
If @ slevel = 'Primary school' -- issue necessary funding based on the level
Set @ zzje = 120
Else if @ slevel = 'Junior high school'
Set @ zzje = 200
Else
Set @ zzje = 500
Insert into t_jzk_use (student_id, zzxq, zzje) values (@ Sid, @ pzzxq, @ zzje) -- the first donation
End
End
End

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.