Hi Experts,
Need your help with the stored procedure logic where we are getting the data from the app and storing it in the UserDetails table.
From the App we can modify the User Address or phone number, how can we update the dynamic column based on what has changed?
I don't understand your question. Can you give a clear example of the data the app is sending you?
You should use some kind of validation to make sure the app is sending correct information. Normally you would give the sp 3 parameters, 1 as userid, 1 for address and 1 for phonennumber. Then you validate both parameters. If it's not valid you should return an error message. If it's valid then you update the table but only if the parameter is different then your data.
Thanks @Rogier for your reply.
There is a web based app which is being used to onboard users.
if there is any record, lets say phone number of the user is being modified, then the user record in the database table should update as well.
My question is that the update can be in Address/Phone number/Department. So the stored procedure code should be dynamic so that it can pick up any column change.
The table name will always be the same, but the column names are variable based on how the front-end application
It can be done with d-sql or you can use something like this:
IF @Address IS NOT NULL
BEGIN
UPDATE tblUsers SET Address=@Address WHERE UserID=@UserID AND Address <> @Address;
END
IF @PhoneNumber IS NOT NULL...
etc.