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
Solved

SQL Question

Posted on 2009-03-31
9
182 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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Query including math and 2 tables problem 26 56
Query still returning duplicates 5 41
Whats wrong in this query - Select * from tableA,tableA 11 45
TSQL Challenge... 7 35
As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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