I would like to call the "update" stored procedure, which will not necessarily include all columns. There is probably a better way to handle this .... As you can see, if I don't pass the column parameters, their value will be NULL. Then, using ISNULL, I set the columns to both my new values ββand their existing values.
CREATE PROCEDURE [dbo].[spUpdateTable]
@pPKID bigint = NULL,
@pColumn1 int = NULL,
@pColumn2 int = NULL
AS
BEGIN
SET NOCOUNT ON;
UPDATE
TableName
SET
[Column1] = ISNULL(@pColumn1,[Column1]),
[Column2] = ISNULL(@pColumn2,[Column2])
WHERE
[PKID] = @pPKID
END
source
share