SQL2005存储过程三张表(A,B,C)判断用户信息(name,pwd)是否存在,if、else如何编写
发布网友
发布时间:2022-08-20 21:38
我来回答
共3个回答
热心网友
时间:2023-11-11 00:45
假如A表放的用户基本信息
create procere sp_checkuser
( @user varchar(20), @pwd varchar(50) )
AS
begin
if exists( select * from A where name = @user and pwd =@pwd)
begin
if exists (select * from B where name=@user and pwd=@pwd )
begin
if exists (select * from C where name=@user and pwd=@pwd)
begin
--此处加入其他代码
end;
end;
end;
热心网友
时间:2023-11-11 00:45
CREATE PROCEDURE 过程名
@user_name VARCHAR(20),
@user_password VARCHAR(20)
AS
BEGIN
IF (SELECT COUNT(*) FROM 表A WHERE user_name = @user_name AND user_password = @user_password)
BEGIN
END
IF (SELECT COUNT(*) FROM 表B WHERE user_name = @user_name AND user_password = @user_password)
BEGIN
END
IF (SELECT COUNT(*) FROM 表C WHERE user_name = @user_name AND user_password = @user_password)
BEGIN
END
END
热心网友
时间:2023-11-11 00:46
这样写就对了,呵呵
ALTER PROCEDURE [dbo].[t_userinfo_Exists]
@user_name nvarchar(50)
AS
DECLARE @TempID int
SELECT @TempID = count(1) FROM [t_userinfo] WHERE [user_name]=@user_name
if @TempID = 0
select 0
else
select 1
或者这样
ALTER PROCEDURE [dbo].[t_userinfo_Exists]
@user_name nvarchar(50)
AS
DECLARE @TempID int ,@returnValue int
set @returnValue=0
SELECT @TempID = count(1) FROM [t_userinfo] WHERE [user_name]=@user_name
if @TempID >0
set @returnValue=1
select @returnValue
以后要返回东西最好都这样写用select,或者用输出参数