Groups | Blog | Home
all groups > sql server new users > march 2006 >

sql server new users : Help with query


Jens
3/23/2006 12:15:04 AM
Update p1,p2
set
p1.value =
CASE WHEN p2.value_ch = 0 THEN p2.value_re
ELSE p2.value_ch
END
Where p1.exam = p2.code

HTH, Jens Suessmeyer.


---
http://www.sqlserver2005.de
---
Luiz Horacio
3/23/2006 12:41:41 AM
Hi,

I have a simple query, that worked fine until I realized I made a stupid
error.

I need to update one table with the value from another table. So I used this
query:

Update p1, p2
set p1.value = p2.value_ch
Where p1.exam = p2.code

The problem is that, on very rare occasions, p2.value_ch = '0', and then I
should update p1 with p2.value_re.

How can I create an 'if...then' with sql?

Thanks,


Luiz Horacio

Luiz Horacio
3/24/2006 11:00:07 PM
Hi Jens,

Thanks. I guess using the same subject sent my post to this thread.

Thanks,

Luiz Horacio


"Jens" <Jens@sqlserver2005.de> escreveu na mensagem
news:1143101704.936572.283930@z34g2000cwc.googlegroups.com...
[quoted text, click to view]

AddThis Social Bookmark Button