I have this table CustomerProfile that has the CustomerId, ProfileId,startDate and endDate. When the user add data to the profile it will insert a record with a startDate and endDate is null. If the user edit the profile I want to see if they make a change so I need to count the record in the table and if it not 0 then I do a check if that option has changed. In the BEGIN section do I need to select the ProfileId and see if it different? can I do that in the CountCustomerProfileId? Any help with this would be great.
Insert default values
insert into [dbo].[CustomerProfile] (CustomerId,ProfileId,startDate,endDate)
values (1,2,2022-09-07,null)
Counts that the users has insert data in the profile table before
DECLARE @CountCustomerProfileId INT
SET @CountCustomerProfileId = (SELECT Count([CustomerProfileId]) as CustomerProfileId
FROM [dbo].[CustomerProfile]
where [CustomerId] = @CustomerId)
BEGIN Code: ProfileId "2,3"
IF @CustomerProfileId > 0
BEGIN
UPDATE [dbo].[CustomerProfile] set endDate = GETDATE()
WHERE CustomerId = @CustomerId
END