我正在尝试在托管在远程服务器上的数据库上重新创建存储过程。 在本地创建相同的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
谢谢,Laziale
答案 0 :(得分:0)
此合并功能适用于sql sever 2008 +版本,如果您尝试在sql server 2005中使用,则可以在2005年执行此类合并模拟
http://sqlserver-tips.blogspot.com/2006/09/mimicking-merge-statement-in-sql.html
答案 1 :(得分:0)
您也可以在CREATE PROCEDURE脚本之前尝试此操作。
USE [MyDatabase] 走 IF EXISTS(SELECT名称来自SysObjects WHERE ID = OBJECT_ID(N'[InsertContractorInfo]')) 开始 DROP PROCEDURE InsertContractorInfo 结束 GO