SQL Update Help for Multiple Records

I have a table called MasterCostCodeList. The two fields in the table are Level3 and Active. I have a query (not shown) that gives me orphaned records that I need to change (will only use five records for my example). So I have the following results:

Level3               Active
MO-1                      1
MO-2                      1
MO-3                      1
MO-4                      1
MO-5                      1

I need to set the active field from 1 to 0. I have the following update statement:

Update dbo.MasterCostCodeList
Set Active='0'
Where Level3='MO-1';

My question is how do I add the remaining level3 records to the statement? I tried the following below but that does not seem to work. What am I missing that is probably so simple.

Update dbo.MasterCostCodeList
Set Active='0'
Where Level3='MO-1', 'MO-2', 'MO-3', 'MO-4', 'MO-5';
DJ PAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Bill PrewCommented:
Try:

Update dbo.MasterCostCodeList
Set Active='0'
Where Level3 In ('MO-1', 'MO-2', 'MO-3', 'MO-4', 'MO-5');

Open in new window

And keep in mind the values in the IN() clause could be the result set of a sub query that identifies the records to update.

»bp
2
Pawan KumarDatabase ExpertCommented:
Please try this- , OR Statement.

IN YOUR QUERY you JUST NEED TO add OR in the WHERE CLAUSE LIKE BELOW.

--

Update dbo.MasterCostCodeList
Set Active='0'
Where Level3 = 'MO-1' OR Level3  =  'MO-2' OR Level3  =  'MO-3' 
OR Level3  =  'MO-4' OR Level3  =  'MO-5'

--

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
DJ PAuthor Commented:
Thanks!
0
Bill PrewCommented:
DJ P,

As always, you get to choose how you want to close a question when there are multiple solutions, but I'm curious, what made you select only the "OR" approach and not the "IN" approach, both should work?


»bp
0
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
SQL

From novice to tech pro — start learning today.