Record several simple stored procedures written by yourself (to prevent syntax forgetting)

Source: Internet
Author: User
Tags rtrim

/**************************************
User Registration
**************************************/
Create procedure regaccount1

@ Playeraccount char (20), --- User Name
@ Playername char (20), --- what is the name of the user?
@ Playerpassword char (20), --- User Password
@ Playerquestion1 int, --- user problems
@ Playeranswer1 char (50), ---- user answer
@ Playersex int, --- user gender
@ Playerbirthday char (30), --- user Date of birth
@ Playerpostcard int ,---
@ Playerpostcode char (20 ),
@ Playeremail char (30), ---- user email
@ Playeruserpwd char (20), ---- User Password
@ Getclientip char (20), ---- user IP
@ Giftcoupon int, ------- newbie package
@ Retuvalue int output -- Return Value

As

Declare
@ Maxplayerid bigint,
@ Checkaccount char (20 ),
@ Checkname char (20 ),
@ Timenow datetime,
@ Uidincreaseoffset int,
@ Maxregcount bigint

Begin
Set @ playerpassword = rtrim (@ playerpassword );
Select @ timenow = getdate ();
Select @ maxplayerid = idvalue + 1 from sumtable where indexid = 501; -- find the maximum playeruid of the current user

If exists (select playeruid from playerid where upper (account) = upper (@ playeraccount) -- determines whether the user's registered user name has been registered
Begin
Set @ retuvalue =-1
Return; -- the account exists
End

Update sumtable set idvalue = @ maxplayerid where indexid = 501;

Begin transaction
Insert into playerid (account,
Playeruid
)
Values (@ playeraccount,
@ Maxplayerid );
If @ rowcount <> 1 goto Error
Insert into playeraccount (playeruid, -- save user information
[Name],
Sex,
Birthday,
-- Province,
-- Addr1,
Email,
IDNO,
Idcase,
-- Phoneno,
Registtime,
Userpassword,
Playerip

)
Values (@ maxplayerid,
@ Playername,
@ Playersex,
Convert (datetime, @ playerbirthday ),
-- @ Playerprovince,
-- @ Playeraddr1,
@ Playeremail,
@ Playerpostcode,
@ Playerpostcard, -- @ playeridno,
-- @ Playerphoneno,
@ Timenow,
Rtrim (@ playeruserpwd ),
@ Getclientip
);
If @ rowcount <> 1 goto Error
Insert into playersecureqa (playeruid,
Question,
Answer)
Values (@ maxplayerid,
@ Playerquestion1,
@ Playeranswer1 );
If @ rowcount <> 1 goto Error

Declare @ date datetime

-- Set @ date = getdate ()

-- Select @ date = dateadd (hour, 16,) -- add 16 hours
Select @ date = dateadd (minute, 1000, getdate () -- add 40 minutes

Insert into playercardpoint (playeruid, -- initialize user Game Information
Cardpoint,
[Password],
Firstlogin,
CardType
-- Bactq modify
, Cardavailabletime
, Giftcoupon
)
Values (@ maxplayerid,
0,
Rtrim (@ playerpassword ),
Convert (datetime, '2017-03-16 '),
0,
-- Bactq modify
@ Date
, @ Giftcoupon
);
If @ rowcount <> 1 goto Error
Commit
Set @ retuvalue = 1
Return;
Error:
Begin
Rollback transaction
Set @ retuvalue =-1
Return
End
End
Go

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.