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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
All Courses

From novice to tech pro — start learning today.