-1

我正在尝试在托管在远程服务器上的数据库上重新创建存储过程。在本地创建相同的 SP 时,我没有收到任何错误,但是当我尝试在远程服务器上创建 SP 时,我收到以下错误:

Msg 102, Level 15, State 1, Procedure MySP, Line 26
Incorrect syntax near 'MERGE'.
Msg 102, Level 15, State 1, Procedure MySP, Line 27
Incorrect syntax near 'S'.

这些错误在多个 SP 中重复出现,当我在本地服务器上创建 SP 时我没有得到它们。知道那会是什么吗?这是一个示例 SP:

USE [MyDatabase]
GO
/****** Object:  StoredProcedure [dbo].[InsertContractorInfo]    Script Date: 11/07/2012 01:08:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
--exec [dbo].[InsertContractorInfo] 
CREATE PROCEDURE [dbo].[InsertContractorInfo]
(@CompanyName nvarchar(50), 
 @LicenseNumber nvarchar(50),
 @MailingAddress1 nvarchar(200),
 @MailingAddress2 nvarchar(200),
 @Phone nvarchar(10),
 @Fax nvarchar(10),
 @Mobile nvarchar(10),
 @Email nvarchar(200),
 @PercentCommercial int,
 @PercentResidental int,
 @TotalEmployees int,
 @AnnualSales decimal(18,2),
 @InsuranceCompanyContact nvarchar(100)=null,
 @InsuranceCompanyContactEmail nvarchar(100)=null,
 @InsuranceCompanyContactPhone nvarchar(100)=null,
 @ContractorID uniqueidentifier)
AS
BEGIN
MERGE dbo.Contractor con
USING(SELECT 1 S) S
ON con.Oid = @ContractorID
WHEN MATCHED THEN UPDATE 
   SET       
      [CompanyName] = @CompanyName      
      ,[LicenseNumber] = @LicenseNumber
      ,[MailingAddress1] = @MailingAddress1
      ,[MailingAddress2] = @MailingAddress2
      ,[Phone] = @Phone
      ,[Fax] = @Fax
      ,[EMail] =@Email
      ,[Mobile] =@Mobile      
      ,[PercentCommercial] = @PercentCommercial
      ,[PercentResidental] = @PercentResidental
      ,[TotalEmployees] = @TotalEmployees
      ,[ApproximateAnnualSales] = @AnnualSales      
      ,[InsuranceCompanyContact] = @InsuranceCompanyContact
      ,[InsuranceCompanyContactPhone] = @InsuranceCompanyContactPhone
      ,[InsuranceCompanyContactEmail] = @InsuranceCompanyContactEmail      
WHEN NOT MATCHED THEN
INSERT 
           ([Oid]       
           ,[CompanyName]           
           ,[LicenseNumber]
           ,[MailingAddress1]
           ,[MailingAddress2]
           ,[Phone]
           ,[Fax]
           ,[EMail]
           ,[Mobile]                      
           ,[PercentCommercial]
           ,[PercentResidental]
           ,[TotalEmployees]
           ,[ApproximateAnnualSales]                      
           ,[InsuranceCompanyContact]
           ,[InsuranceCompanyContactPhone]
           ,[InsuranceCompanyContactEmail])
     VALUES
           (@ContractorId           
           ,@CompanyName           
           ,@LicenseNumber
           ,@MailingAddress1
           ,@MailingAddress2
           ,@Phone
           ,@Fax
           ,@EMail
           ,@Mobile
           ,@PercentCommercial
           ,@PercentResidental
           ,@TotalEmployees
           ,@AnnualSales                     
           ,@InsuranceCompanyContact
           ,@InsuranceCompanyContactPhone
           ,@InsuranceCompanyContactEmail
           );
END
GO

谢谢,拉齐尔

4

2 回答 2

0

您也可以在 CREATE PROCEDURE 脚本之前尝试此操作。

USE [MyDatabase] GO IF EXISTS(SELECT Name FROM SysObjects WHERE ID = OBJECT_ID(N'[InsertContractorInfo]')) BEGIN DROP PROCEDURE InsertContractorInfo END GO

于 2012-11-07T05:50:15.007 回答
0

此合并功能适用于 sql sever 2008 + 版本,如果您尝试在 sql server 2005 中使用,您可以在 2005 中执行此合并模拟

http://sqlserver-tips.blogspot.com/2006/09/mimicking-merge-statement-in-sql.html

于 2012-11-07T00:41:42.050 回答