We help IT Professionals succeed at work.
Get Started

Multiple Update Queries in the Same Stored Procedure

JoeMiskey
JoeMiskey asked
on
817 Views
Last Modified: 2012-05-10
I am trying to put two update queries in the same stored procedure.  The structure of this stored procedure looks like this:
USE [database name]
GO

ALTER PROCEDURE [dbo].[stored procedure name]
   as
BEGIN

UPDATE
   ...
SET
   ...
FROM
   ...
LEFT OUTER JOIN
   ...
ON
   ...
WHERE
   ...

UPDATE
   ...
SET
   ...
FROM
   ...
INNER JOIN
   ...
ON
   ...
WHERE
   ...

END

Open in new window

As long as there are records to update by both update statements, it seems to work fine.  However, if the conditions exists where there are no records to update in the first update statement, but there are some to update with the second update statement, it doesn't work.  No records get updated in this situation.  Its like since it cannot find any records to update with the first statement, it quits and never gets to the second update statement.

Can someone tell me how to fix this?
Thanks
Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE