Stored Procedure Update Table where @parameter = 1 sql 2005

I am passing in a variable @processid to a stored procedure and I want to set a field in a table to 1 based on the value

I keep getting errors and I dont know what is wrong.

help with my code please
@processid int
 
update sales_jobentry 
case 
when  @processid = 0 then set [0] = 1
when  @processid =  1 then set [1] = 1
when  @processid =  2 then set [2] = 1
when  @processid =  3 then set [3] = 1
when  @processid =  4 then set [4] = 1
when  @processid =  5 then set [5] = 1
when  @processid =  6 then set [6] = 1
when  @processid =  7 then set [7] = 1
when  @processid =  8 then set [8] = 1
end 
where jobnumber = @jobnumber

Open in new window

logoncomAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

3abqariCommented:
What's the structure of the sales_jobentry?
0
3abqariCommented:
and where are you declaring the @jobnumber?
0
logoncomAuthor Commented:
the number in [ ] are fields in my table that I want to set to 1 or 0.

I'm trying to accomplish this using a case statement depending on what @processid equals.

My query syntax is wrong and want to know how it should be written.  Full SP attached
ALTER PROCEDURE [dbo].[SP_updatesalesjobentrytable]
 
@processid int,
@jobnumber int
 
AS
BEGIN
 
 
	SET NOCOUNT ON;
 
   
delete from dbo.Data_EmployeeTaskList where jobnumber = @jobnumber
and Step = @processid
 
Insert into  dbo.CompletedDataProcesses (processid,jobnumber)
   values (@processid,@jobnumber)
 
 
update sales_jobentry 
 
case 
when  @processid = 0 then set [0] = 1
when  @processid =  1 then set [1] = 1
when  @processid =  2 then set [2] = 1
when  @processid =  3 then set [3] = 1
when  @processid =  4 then set [4] = 1
when  @processid =  5 then set [5] = 1
when  @processid =  6 then set [6] = 1
when  @processid =  7 then set [7] = 1
when  @processid =  8 then set [8] = 1
end 
where jobnumber = @jobnumber
 
END
 
 
  

Open in new window

0
logoncomAuthor Commented:
Nevermind... I figured it out



If @processid = 0
 
BEGIN
	SET NOCOUNT ON;
 
update sales_jobentry
set [0] = 1 
where jobnumber = @jobnumber
 
 
END
 
ELSE
 
if @processid = 1
BEGIN
	SET NOCOUNT ON;
update Sales_JobEntry
set [1] = 1
where jobnumber = @jobnumber
 
END
 
 
 
ELSE
 
if @processid = 2
BEGIN
	SET NOCOUNT ON;
update Sales_JobEntry
set [2] = 2
where jobnumber = @jobnumber
 
END
 
ELSE
 
if @processid = 3
BEGIN
 
update Sales_JobEntry
set [3] = 1
where jobnumber = @jobnumber
	SET NOCOUNT ON;
END
 
ELSE
 
if @processid = 4
BEGIN
	SET NOCOUNT ON;
update Sales_JobEntry
set [4] = 1
where jobnumber = @jobnumber
 
END
 
 
 
ELSE
 
if @processid = 5
BEGIN
	SET NOCOUNT ON;
update Sales_JobEntry
set [5] = 1
where jobnumber = @jobnumber
 
END
 
 
 
 
 
 
 
 
ELSE
 
if @processid = 6
BEGIN
	SET NOCOUNT ON;
update Sales_JobEntry
set [6] = 1
where jobnumber = @jobnumber
 
END
 
 
ELSE
 
if @processid = 7
BEGIN
	SET NOCOUNT ON;
update Sales_JobEntry
set [7] = 1
where jobnumber = @jobnumber
 
END
 
 
 
ELSE
 
if @processid = 8
BEGIN
	SET NOCOUNT ON;
update Sales_JobEntry
set [8] = 1
where jobnumber = @jobnumber
 
END

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.

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.