0

ネストされた if ステートメント ストアド プロシージャがありますが、エラーが発生しています。

メッセージ 102、レベル 15、状態 1、手順 SPCRMDoctorRequestList、行 28
'DR' 付近の構文が正しくありません。

それは2番目のifステートメントのelse部分にあります

これが私のストアドプロシージャです:

CREATE PROCEDURE [dbo].[SPCRMList]
@Records INT,
@Type VARCHAR(10),  /*Recent, Priority, Pending, Approved*/
@ViewType VARCHAR(10)   /*Dashboard, List*/
AS
BEGIN
SET NOCOUNT ON
IF (@Type = 'Recent')
BEGIN
    IF(@ViewType = 'Dashboard')
    BEGIN
        Select top (@Records)
        DR.Id AS Id,    /*Unique ID*/
        USERS.USERNAME AS Requester_Name,       /*Employee Name*/
        ST.ServiceName AS Service_Type_Name,    /*Nature of Service*/
        DR.Date_Created AS Date_Created    /*Created Date*/
        From [Doctor_Request] AS DR
        JOIN [ASES].[dbo].[USERS] AS USERS
        ON DR.Requester COLLATE SQL_Latin1_General_CP1_CI_AS = USERS.RID COLLATE SQL_Latin1_General_CP1_CI_AS
        JOIN [SERVICE_TYPE] AS ST
        ON DR.Service_Type_Id=ST.Id
        WHERE DR.Is_Deleted=0
        ORDER BY DR.Date_Created DESC
    END
    ELSE IF (@ViewType = 'List')
    BEGIN
        Select top (@Records)
        DR.Id AS Id,    /*Unique ID*/
        USERS.USERNAME AS Requester_Name,       /*Employee Name*/
        ST.ServiceName AS Service_Type_Name,    /*Nature of Service*/
        DR.Date_Created AS Date_Created    /*Created Date*/
            DR.State AS State /*State of Request*/
            DR.Deadline AS Deadline /*Deadline of request*/
        From [Doctor_Request] AS DR
        JOIN [USERS] AS USERS
        ON DR.Requester COLLATE SQL_Latin1_General_CP1_CI_AS = USERS.RID COLLATE SQL_Latin1_General_CP1_CI_AS
        JOIN [SERVICE_TYPE] AS ST
        ON DR.Service_Type_Id=ST.Id
        WHERE DR.Is_Deleted=0
        ORDER BY DR.Date_Created DESC
    END
END
4

1 に答える 1

3

両方のクエリDRでテーブル エイリアスを定義していません。たとえば、次のようになります

Select DR.colName, X.colName
from Table1 DR join Table2 X on DR.id = X.id
...

また、2 番目のクエリcommasでは、次の列の後にDate_Created... asを追加する必要があります。

SELECT ...
    DR.Date_Created AS Date_Created,    /*Created Date*/
    DR.State AS State, /*State of Request*/
    DR.Deadline AS Deadline /*Deadline of request*/
FROM ...
于 2013-02-12T12:11:14.107 に答える