关键字' UPDATE'附近的语法不正确

时间:2016-05-12 13:21:25

标签: sql sql-server

请执行以下步骤并在更新时出现语法错误:

USE [OTIDatabaseNewOutreach_V3.2.0_BESQL]
GO
/****** Object:  StoredProcedure [dbo].[usp_OTIDataImportConstruction_U]    Script Date: 5/12/2016 8:44:18 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[usp_OTIDataImportConstruction_U]

    UPDATE dbo.[OTI Trainer Data Import]  
    SET [Construction Industry Card #] = IsNull([c_cardnumberissued],[TrainerIDNumber]),
        [Construction Date Issued] = [tblCourse].[c_enddate]
    from tblCourse
    inner JOIN dbo.tblCourseToStudent ON dbo.tblCourse.c_id = dbo.tblCourseToStudent.c_id 
    INNER JOIN
            dbo.[OTI Trainer Data Import] ON dbo.tblCourseToStudent.t_id = dbo.[OTI Trainer Data Import].t_id
    WHERE (c_program ='construction') AND (c_expdate>GetDate());

go      

............................................... ........................

2 个答案:

答案 0 :(得分:4)

看起来像SQL Server。 as后需要create procedure。请参阅手册:https://msdn.microsoft.com/en-za/library/ms187926.aspx

答案 1 :(得分:1)

USE [OTIDatabaseNewOutreach_V3.2.0_BESQL] GO /****** Object: StoredProcedure [dbo].[usp_OTIDataImportConstruction_U] Script Date: 5/12/2016 8:44:18 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO

CREATE PROCEDURE [dbo].[usp_OTIDataImportConstruction_U] 
AS
BEGIN

UPDATE dbo.[OTI Trainer Data Import]  
    SET [Construction Industry Card #] = IsNull([c_cardnumberissued],[TrainerIDNumber]),
        [Construction Date Issued] = [tblCourse].[c_enddate]
    from tblCourse
        inner JOIN dbo.tblCourseToStudent ON dbo.tblCourse.c_id = dbo.tblCourseToStudent.c_id INNER JOIN
            dbo.[OTI Trainer Data Import] ON dbo.tblCourseToStudent.t_id = dbo.[OTI Trainer Data Import].t_id
    WHERE (c_program ='construction') AND (c_expdate>GetDate());

END
GO