我在我的存储过程中使用了SQL Server MERGE
语句,在编译存储过程时出现了这样的错误:
对象参考[dbo]。[学生]。[ID]仅根据具体情况而有所不同 对象定义[dbo]。[学生]。[Id]。
我的表结构是:
CREATE TABLE [dbo].[Student]
(
[Id] INT NOT NULL,
[FirstName] VARCHAR (50) NULL,
[LastName] VARCHAR (50) NULL,
[StateID] INT NULL,
[CityID] INT NULL,
[IsActive] BIT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
)
我的存储过程是:
CREATE PROCEDURE [dbo].USP_UpdateStudent
AS
Declare @Data xml
SET @Data = '<?xml version="1.0" encoding="utf-16"?>
<Students>
<Student>
<ID>2</ID>
<FirstName>Tridip</FirstName>
<LastName>Bhattacharjee</LastName>
<IsActive>true</IsActive>
<StateID>2</StateID>
<CityID>4</CityID>
</Student>
</Students>'
BEGIN TRY
MERGE INTO Student as Trg
USING (SELECT
d.x.value('id[1]', 'varchar(MAX)') as ID,
d.x.value('FirstName[1]', 'varchar(MAX)') as FirstName ,
d.x.value('LastName[1]', 'varchar(MAX)') as LastName,
d.x.value('StateID[1]','int') as StateID,
d.x.value('CityID[1]','int') as CityID,
d.x.value('IsActive[1]','bit') as IsActive
FROM
@data.nodes('/Students/Student') as d(x)) AS Src ON Trg.ID = Src.ID
WHEN MATCHED THEN
UPDATE
SET Trg.FirstName = Src.FirstName,
Trg.LastName = Src.LastName,
Trg.StateID = Src.StateID,
Trg.CityID = Src.CityID,
Trg.IsActive = Src.IsActive
WHEN NOT MATCHED BY TARGET THEN
INSERT (FirstName, LastName, StateID, CityID, IsActive)
VALUES(Src.FirstName, Src.LastName, Src.StateID, Src.CityID, Src.IsActive);
END TRY
BEGIN CATCH
-- Insert Error into table
--INSERT INTO #error_log(message)
--VALUES (ERROR_MESSAGE());
END CATCH
导致此错误的错误是什么?感谢
通过SSMS和LinqPad连接sql compact db有2个很好的链接。这是链接
https://stackoverflow.com/a/16692386/728750 https://dba.stackexchange.com/questions/47534/how-do-i-view-a-microsoft-sql-server-compact-database
由于