0

目前我正在验证用户登录,因此使用程序将用户名和密码与注册表单进行比较,然后找到记录集值>0(成功)或<0(失败),但我对程序概念不太了解,我尽力了我的水平,但我无法解决这个问题,请帮助我。提前致谢

在这里我试过这个:

Create table signupform (username varchar(10), password varchar(10)); 
Insert into signupform values ('sampath','s96000');
Insert into signupform values ('yuvaraj','y96297');
select * from signupform;

// CREATE PROCEDURE for compare username and password
create procedure testing (@username varchar(10), @password varchar(10))
AS
BEGIN
select * from signupform where username = @username and password = @password
End;
4

4 回答 4

5

我建议你创建函数:

create function testing(@username varchar(10), @password varchar(10))
RETURNS bit
BEGIN
   if EXISTS(select * from signupform where username = @username and password = @password)
   then
      return 1;
   else
      return 0; 
   end if;
end;
于 2012-06-29T15:13:55.217 回答
0

尝试检查您的用户表中是否存在某些登录名/密码

if EXISTS(SELECT TOP 1 * FROM signupform WHERE username = @username AND password = @password)
begin

set @res = 1;
end

    select @res as valid
    return
于 2012-06-29T15:13:37.163 回答
0

您可以确保无论如何都返回一个值,这样您就不必担心计算行数

IF EXISTS(  
   SELECT *  
   FROM signupform  
   WHERE username = @username AND password = @password)  
BEGIN  
   SELECT 'Y'  
END  
ELSE  
BEGIN  
   SELECT 'N'  
END

或者做一个计数,虽然效率可能较低

SELECT COUNT(*)  
FROM signupform  
WHERE username = @username AND password = @password
于 2012-06-29T15:14:07.793 回答
-1

试试这些SELECT语句:

SELECT UPPER(LEFT(@TypeName, 3)) into @TypeCode;
SELECT UPPER(LEFT(BranchName, 3)) into @Branch from tbl_erp_branches where BranchId=BranchIds;
-- SELECT UPPER(LEFT(AccountHeadName, 3)) into @Head from fin_erp_account_head where AccountHeadId=AccountHeadIds;
SELECT UPPER(LEFT(AccountHeadName, 3)) into @Head from fin_erp_account_head where AccountHeadId=AccountHeadIds;
SELECT UPPER(LEFT(CurrencyCode, 3)) into @Currency from tbl_erp_currency where CurrencyId=CurrencyIds;
于 2015-07-22T10:45:20.603 回答