'='附近的语法不正确

时间:2018-07-10 06:26:09

标签: sql-server tsql stored-procedures

我正在使用SQL Server存储过程,但是在SQL Case中遇到语法错误。

这是我的存储过程代码:

ALTER PROCEDURE [dbo].[spSelectServiceRequest]
AS
BEGIN
    SELECT 
        [id],
        [ServiceID],
        [fullName],
        [email], [mobile],
        [address],
        [serviceNeed],
        [problem],
        [serviceDate],
        [createdOn],
        [status] = CASE [status]
                      WHEN '1' THEN 'New Request'
                      WHEN '2' THEN 'Pending'
                      WHEN '3' THEN 'Accept By Provider'
                      ELSE 'Close'
                   END
    FROM 
        [tblBookingDetail]
    ORDER BY 
        [createdOn] DESC;
END;

任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:1)

尝试一下:

ALTER PROC [dbo].[spSelectServiceRequest]
AS
    BEGIN
        SELECT 
            [id]
          , [ServiceID]
          , [fullName]
          , [email]
          , [mobile]
          , [address]
          , [serviceNeed]
          , [problem]
          , [serviceDate]
          , [createdOn]
          ,  CASE [status]
                           WHEN '1'
                           THEN 'New Request'
                           WHEN '2'
                           THEN 'Pending'
                           WHEN '3'
                           THEN 'Accept By Provider'
                           ELSE 'Close'
                       END AS [status]
        FROM [tblBookingDetail]
        ORDER BY 
            [createdOn] DESC;
    END;

答案 1 :(得分:1)

您查询中的次要语法问题:

ALTER PROC [dbo].[spSelectServiceRequest]
AS
    BEGIN
        SELECT 
            [id]
          , [ServiceID]
          , [fullName]
          , [email]
          , [mobile]
          , [address]
          , [serviceNeed]
          , [problem]
          , [serviceDate]
          , [createdOn]
          , CASE [status]
                           WHEN '1'
                           THEN 'New Request'
                           WHEN '2'
                           THEN 'Pending'
                           WHEN '3'
                           THEN 'Accept By Provider'
                           ELSE 'Close'
                       END AS [Status]
        FROM [tblBookingDetail]
        ORDER BY 
            [createdOn] DESC;
    END;

答案 2 :(得分:0)

 ALTER PROC [dbo].[spSelectServiceRequest]
 AS
 BEGIN
    SELECT id
    ,ServiceID
    ,fullName
    ,email
    ,mobile
    ,address
    ,serviceNeed
    ,problem
    ,serviceDate
    ,createdOn
    ,CASE STATUS
        WHEN '1'
            THEN 'New Request'
        WHEN '2'
            THEN 'Pending'
        WHEN '3'
            THEN 'Accept By Provider'
        ELSE 'Close'
        END
     FROM tblBookingDetail
     ORDER BY createdOn DESC
 END

尝试一下。希望它能起作用。