我是SQL存储过程的新手。我需要编写一个SQL来检查多个表中是否存在电子邮件。如果电子邮件包含在First Table中,则返回true,不应执行其余操作。如果不是,我需要检查第二个表,如果我发现返回true。最后如果我在最后一个表中找到我需要返回true,否则我需要返回false。
我无法实现这一目标。我试过这样的。给我语法错误。请与我分享一个解决方案。
RequestBringIntoView
答案 0 :(得分:2)
USE Users_UserDetials;
GO
CREATE PROCEDURE Users.GetUserPermissions
@userEmail nvarchar(50),
@areaId nvarchar(10),
@villageCode nvarchar(10)
AS
SET NOCOUNT ON;
IF EXISTS (SELECT 1 FROM Users.GlobalUsers AS GU
WHERE GU.UserEmail = @userEmail)
BEGIN
SELECT 1
END
ELSE
IF EXISTS (SELECT 1 FROM Users.AreaSpecificUsers AS AU
WHERE AU.UserEmail = @userEmail)
BEGIN
SELECT 1
END
ELSE
IF EXISTS (SELECT 1 FROM Users.VillageSpecificUsers AS VU
WHERE VU.UserEmail = @userEmail)
BEGIN
SELECT 1
END
ELSE
BEGIN
SELECT 0
END
END