Solved

SQL Question

Posted on 2009-03-31
9
179 Views
Last Modified: 2012-05-06
Hello

I have a datatable where I want to update some entries.

So I just use Update......

But one new entry depends on an existing entry. SO I update several entries and one entry I only update if the entry itself is already "1".

How can I do that?

THanks
0
Comment
Question by:Ruttensoft
  • 4
  • 3
  • 2
9 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24028874
Can you elaborate on what you are trying to do, and provide an example?
0
 

Author Comment

by:Ruttensoft
ID: 24028908
:-) I knew my question is not really clear, sorry :-)

Ok I have a table with following entries:

A            B             C            D
Hello      Test         1            Test2

Now I am updateing it, Update xxxx set A = '....' , B = '...' C = '2 But ONLY if C is 1'

Thanks
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24028927
Does this work:

UPDATE SomeTable
SET A = '....', B = '...', C = 2
WHERE C = 1

?
0
 
LVL 41

Expert Comment

by:ralmada
ID: 24028983

This will update all records, but column C will get updated only if C = 1
UPDATE SomeTable
SET A = '....', B = '...', C = (case when C = 1 then 2 else 1 end)
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:Ruttensoft
ID: 24028984
Hm yes but I want to update the table also if C is not 1, but then I will not set C to 2...

I can use multiple queries but if it's possible then I want to use only one (because I'm on a mobile device with limited speed)
0
 

Author Comment

by:Ruttensoft
ID: 24028991
btw I have another WHERE which points to a single datarow
0
 
LVL 41

Expert Comment

by:ralmada
ID: 24028993
Have you tried mine?
0
 

Author Comment

by:Ruttensoft
ID: 24029123
Thanks didnt see it

I've changed it a bit to:

UPDATE SomeTable
SET A = '....', B = '...', C = (case when C = 1 then 2 else C end)

so it seems to worke (Else C, so it uses the same value as was before)

Thanks a lot!
0
 
LVL 41

Accepted Solution

by:
ralmada earned 500 total points
ID: 24029310
yeah, typo.  The correct one is with the C.
UPDATE SomeTable
SET A = '....', B = '...', C = (case when C = 1 then 2 else C end)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now