How to create a SP to update multiple fields at once?

How to create a SP to update multiple fields at once?

I have the following code but its not working.

CREATE PROCEDURE [dbo].[edit_notes]

    @COMID INT,
	@visible INT,
    @comments NVARCHAR(MAX),
    @updatedby INT,
    @lastupdate DATETIME,
    @commby BIT,
    @importance INT,
    @visibleemployer BIT
AS
UPDATE dbo.Casecomments
    Set Visible = @visible
    Set Comments = @comments
    Set Updatedby = @updatedby
    Set Lastupdate = @lastupdate
    Set @commby = @commby
    Set @importance = @importance
    Set @visibleemployer = @visibleemployer

WHERE COMMID = @COMID
 

Open in new window

LVL 1
AleksAsked:
Who is Participating?
 
Dean ChafeeIT/InfoSec ManagerCommented:
looks like your UPDATE syntax is wrong, should be:

UPDATE dbo.Casecomments
    Set Visible = @visible,
    Comments = @comments,
     Updatedby = @updatedby,
     Lastupdate = @lastupdate,
    commby = @commby,
     importance = @importance,
     visibleemployer = @visibleemployer

WHERE COMMID = @COMID
0
 
AleksAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.