我MERGE
在存储过程中使用了 SQL Server 语句,并且在编译存储过程时出现此错误:
对象引用 [dbo].[Student].[ID] 仅在大小写上与对象定义 [dbo].[Student].[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 获得了 2 个连接 sql compact db 的良好链接。链接在这里
https://stackoverflow.com/a/16692386/728750 https://dba.stackexchange.com/questions/47534/how-do-i-view-a-microsoft-sql-server-compact-database
谢谢