Hi @Paulo , thank you for your time in Office Hours today.
We tried using the GUI setup during Office Hours, but were running into IDENTITY_INSERT issues (which is why I was trying the json/parameters approach with sql instead of GUI) from the original post.
The problem is with jsUpsertContacts and spUpsertContacts. I also created a vTemp variable for debugging jsUpsertContacts if it's helpful.
Here are the table defs and app json export.
TableDefs:
/****** Object: Table [dbo].[Customer] Script Date: 2/6/2025 2:20:53 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Customer](
[CustomerID] [int] IDENTITY(1,1) NOT NULL,
[CustomerName] nvarchar NOT NULL,
[CustomerType] [int] NULL,
CONSTRAINT [PK__Customer__A4AE64B832E4977B] PRIMARY KEY CLUSTERED
(
[CustomerID] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[Contacts] Script Date: 2/6/2025 2:20:22 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Contacts](
[ContactId] [int] IDENTITY(1,1) NOT NULL,
[CustomerId] [int] NOT NULL,
[FirstName] nvarchar NOT NULL,
[LastName] nvarchar NOT NULL,
[PhoneNumber] varchar NULL,
CONSTRAINT [Contacts_pk] PRIMARY KEY CLUSTERED
(
[ContactId] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Contacts] WITH CHECK ADD CONSTRAINT [Contacts_Customer_CustomerID_fk] FOREIGN KEY([CustomerId])
REFERENCES [dbo].[Customer] ([CustomerID])
GO
ALTER TABLE [dbo].[Contacts] CHECK CONSTRAINT [Contacts_Customer_CustomerID_fk]
GO
APP Json
CustomerDB.json (73.3 KB)
Where we left off in Office Hours was that even though we removed the ContactId field from the targetRow object, it was still trying to pass ContactId on insert.
Thank you for hosting Office Hours and for your time.
Will