Credit level storage process

Source: Internet
Author: User

Exec setscores 'test', 'test'

Alter proc setscores (@ username varchar (120), @ password varchar (120 ))
As
Begin
Declare @ count int
Declare @ lastdate datetime
Declare @ GID varchar (60)
Declare @ sum int
Declare @ level varchar (60)
--- Annual variable
Declare @ regdate datetime
Declare @ yearcount int
--- Function topic
Select @ gid = GID from cususers where [user_name] = @ username
Select @ COUNT = count (1) From cususers where [user_name] = @ username and user_pass = @ Password
If (@ count> 0)
Begin
Select @ lastdate = gdate from userscrores where uid = @ GID and stype = 1 order by gdate DESC
Set @ lastdate = isnull (@ lastdate, getdate ()-1)
If (datediff (day, @ lastdate, getdate ()> = 1)
Begin
-- Add logon logs
Insert into userscrores (stype, uid, scores) Select '1', @ GID, 10

end
-- Annual score Settings
select @ regdate = gdate from cususers where gid = @ GID
set @ yearcount = datediff (year, @ regdate, getdate ()
If (@ yearcount> = 0)
begin
Print '10'
Update userscrores set scores = 50 where uid = @ GID and stype = 10
If (@ rowcount <= 0)
insert into userscrores (stype, uid, scores) Select '10', @ GID, 50
end
else if (@ yearcount> = 1 and @ yearcount <= 2)
begin
Update userscrores set scores = 50 where uid = @ GID and stype = 11
If (@ rowcount <= 0)
insert into userscrores (stype, uid, scores) Select '11', @ GID, 50
end
else if (@ yearcount> = 3)
begin
Update userscrores set scores = 50 where uid = @ GID and stype = 12
If (@ rowcount <= 0)
insert into userscrores (stype, uid, scores) Select '12', @ GID, 50
end

--- Set level
Select @ sum = sum (isnull (scores, 0) from userscrores where uid = @ GID
Select @ level = levelmark from leveltable where @ sum between sstart and send
Update cususers set ulevel = @ level where gid = @ GID
-- Set end
End

End

Go

Select * From leveltable

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.