Solved

SQL Question

Posted on 2009-03-31
9
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

729 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