How can I run an UPDATE like below where it only updates the columns that are not null?
UPDATE Table
SET Name = @Name,
Email = @Email,
Phone = @Phone
WHERE id = @id
Edit:
So if I’m using the above update but the following is assigned…
@Name = Tom
@Email = NULL
@Phone = NULL
So only Name would be updated and whatever was in the database for Email and Phone will remain in the database as such.
This basic idea should work:
So if
@Nameis NULL,Nameis unchanged. If@Nameis not NULL, it is assigned toNameetc…— EDIT —
Sure @clintp, the COALESCE variant would look like this: