SQL Question

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
RuttensoftAsked:
Who is Participating?
 
ralmadaConnect With a Mentor Commented:
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
 
Patrick MatthewsCommented:
Can you elaborate on what you are trying to do, and provide an example?
0
 
RuttensoftAuthor Commented:
:-) 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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Patrick MatthewsCommented:
Does this work:

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

?
0
 
ralmadaCommented:

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
 
RuttensoftAuthor Commented:
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
 
RuttensoftAuthor Commented:
btw I have another WHERE which points to a single datarow
0
 
ralmadaCommented:
Have you tried mine?
0
 
RuttensoftAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.