-2

我创建了一个存储过程来根据传递给参数的某些值检索一些详细信息。这需要在存储过程执行的 SQL 之间进行切换。以下是代码:

USE [DFS]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[DAFS]
@EmailID Nvarchar(128),
@clientID int,
@userType Varchar(50),
@Success numeric output, 
@msg varchar(100) output  

AS

BEGIN
    if @userType='Normal User'
        IF EXISTS (SELECT 1 FROM dbo.Allcdn 
                    WHERE EmailID = @EmailID AND ClientID = @clientID) 
            begin
                set @Success=0
                set @msg='Carry on ....'
            end
        else
            begin
                set @Success=6  
                set @msg='Not allowed ...' 
            END
        end
    else
        Begin
            IF EXISTS (SELECT 1 FROM dbo.Alcon 
                        WHERE EmailID = @EmailID AND ClientID = @clientID) 
                BEGIN
                    set @Success=0
                    set @msg='Carry on...' 
                END 
            END
        End
    end
END

整个处理基于变量@userType。不知道为什么存储过程没有编译。

4

1 回答 1

4

格式化是您的朋友,只需快速浏览一下,您的 s 似乎就太多了END——请参阅SQL Fiddle with working Demo

CREATE PROCEDURE [dbo].[DAFS]
  @EmailID Nvarchar(128),
  @clientID int,
  @userType Varchar(50),
  @Success numeric output, 
  @msg varchar(100) output  

AS
BEGIN
  if @userType='Normal User'
    IF EXISTS (SELECT 1 FROM dbo.Allcdn 
                WHERE EmailID = @EmailID AND ClientID = @clientID) 
      begin
        set @Success=0
        set @msg='Carry on ....'
      end
    else
      begin
        set @Success=6  
        set @msg='Not allowed ...' 
      END
  else
    Begin
      IF EXISTS (SELECT 1 FROM dbo.Alcon 
                    WHERE EmailID = @EmailID AND ClientID = @clientID)
        BEGIN
          set @Success=0
          set @msg='Carry on...' 
        END 
    END
end
于 2012-10-08T20:44:11.510 回答