存貯過程(SQL樣版)
今天發(fā)個SQL存貯過程給大家認(rèn)識
復(fù)制代碼 代碼如下:
CREATE PROCEDURE login_verify
(
@community_id int, --拿值
@username varchar(20),
@password varchar(40),
@result tinyint output
)
AS
set nocount ON
declare @service_deadline_date smalldatetime,@community_setting_max_online_count int ---定義一個變量為 短日期格式
select @community_setting_max_online_count=community_setting_max_online_count,@service_deadline_date=service_deadline_date from community_info where community_id=@community_id --這里是求最大登錄人數(shù)
if datediff(d,@service_deadline_date,getdate())>10 --其實(shí)這個是限制用戶的使用期,求當(dāng)前日期與庫中的記錄日期如時大于10天,則返回@result =11
begin
set @result=11 --超過使用期
return
end
if (select count(*) from online_user where =@community_setting_max_online_count">community_id=@community_id)>=@community_setting_max_online_count --根據(jù)庫中的記錄設(shè)定與當(dāng)前人數(shù)比較
begin
set @result=10 --超出在線人數(shù)限制 --返回@result=10
return
end
declare @stamia int,@last_update_stamia_date smalldatetime,@level_id int --定義變量 整型 短日期型 整型
declare @userid int ,@user_role int
select @userid=userid,@user_role=user_role,@stamia=stamia,@last_update_stamia_date=last_update_stamia_date,@level_id=level_id from user_info where username=@username and password=@password and community_id=@community_id and user_type=0
--從用戶信息表中,將一些信息寫入到定義的三個變量中
if @userid is not null ----如果@userid 不變null值
begin --用戶名和密碼校驗(yàn)成功
set @result=1 --檢驗(yàn)成功
return
end
else
begin
set @result=0 ---登錄失敗
end
set nocount OFF
GO
我們給上面的過程取個名login_verify叫做
寫成是ASP代碼中調(diào)用安全認(rèn)證的地方
'''事先已經(jīng)定義好conn
Set cmd.ActiveConnection=conn
cmd.CommandText="login_verify"
cmd.CommandType=H0004
@community_id int, --拿值
@username varchar(20),
@password varchar(40),
@result int
cmd.Parameters.Append cmd.CreateParameter("@community_id",3)
cmd.Parameters.Append cmd.CreateParameter("@username ",200)
cmd.Parameters.Append cmd.CreateParameter("@password",200)
cmd("@community_id")=session("community_id")
cmd("@username")=request("userid")
cmd("@password")=request("userid")
cmd.execute
dim result
result=cmd("@result")
conn.close
if trim(result)="1" then
'''''''''''''登錄成功的提示與操作
else
''''''''''''''''''''''登錄失敗的提示與操作
end if