存貯過程(SQL樣版)
今天發個SQL存貯過程給大家認識
復制代碼 代碼如下:
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 --這裡是求最大登錄人數
if datediff(d,@service_deadline_date,getdate())>10 --其實這個是限制用戶的使用期,求當前日期與庫中的記錄日期如時大於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 --根據庫中的記錄設定與當前人數比較
begin
set @result=10 --超出在線人數限制 --返回@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 --用戶名和密碼校驗成功
set @result=1 --檢驗成功
return
end
else
begin
set @result=0 ---登錄失敗
end
set nocount OFF
GO
我們給上面的過程取個名login_verify叫做
寫成是ASP代碼中調用安全認證的地方
'''事先已經定義好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