A
A
artshelom2021-06-22 23:22:39
SQL
artshelom, 2021-06-22 23:22:39

How to use merge into?

I'm trying to make a merge into request, it seems to me that I have an old version of the database:

MERGE INTO [dbo].[CinemaUsers] t
  USING (SELECT * FROM OPENJSON('[{"ID":1,"UserName":"Администратор","LoweredUserName":"администратор","DisplayName":"","Inn":"","PinCode":"","Enabled":true,"Deleted":false,"Guid":"f052b53f-d6ec-45c5-8734-0e0dd7b0d2f1","serverId":null}]')
  with ([ID] int, [UserName] nvarchar, [Enabled] bit, [Deleted] bit, [Guid] uniqueidentifier, [LoweredUserName] nvarchar, [DisplayName] nvarchar, [Inn] nvarchar, [PinCode] nvarchar, [CardCode] bigint, [ExternalId] int, [serverId] int)) 
  j ON (t.[ID] = j.[serverId])
  WHEN MATCHED THEN update set t.[UserName] = j.[UserName], t.[Enabled] = j.[Enabled], t.[Deleted] = j.[Deleted], t.[Guid] = j.[Guid], t.[LoweredUserName] = j.[LoweredUserName], t.[DisplayName] = j.[DisplayName], t.[Inn] = j.[Inn], t.[PinCode] = j.[PinCode], t.[CardCode] = j.[CardCode], t.[ExternalId] = j.[ExternalId] 
  WHEN NOT MATCHED THEN INSERT ([UserName], [Enabled], [Deleted], [Guid], [LoweredUserName], [DisplayName], [Inn], [PinCode], [CardCode], [ExternalId]) values (j.[UserName], j.[Enabled], j.[Deleted], j.[Guid], j.[LoweredUserName], j.[DisplayName], j.[Inn], j.[PinCode], j.[CardCode], j.[ExternalId]) 
  output $action, inserted.ID, j.[ID];

I am getting an error:

Неправильный синтаксис около ключевого слова "with". Если эта инструкция является обобщенным табличным выражением, предложением xmlnamespaces или предложением в контексте отслеживания изменений, предыдущую инструкцию необходимо завершить точкой с запятой.


It seems like the table needs to be updated to 1003, but I don’t remember how or is there something else?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question