[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 26
  • Last Modified:

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';
0
DJ P
Asked:
DJ P
  • 2
1 Solution
 
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
 
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

Join & Write a Comment

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now