all groups > sql server new users > march 2006 >
You're in the

sql server new users

group:

Help - SQL


Re: Help - SQL Mike Hodgson
3/23/2006 12:00:00 AM
sql server new users:
Use the CASE predicate like this:

update p1
set p1.value =
case
when p2.value_ch = '0' then p2.value_re
else p2.value_ch
end
from p1
inner join p2 on p1.exam = p2.code

NB/ I changed your SQL-89 join syntax to the more current SQL-92 join
syntax.

--
*mike hodgson*
http://sqlnerd.blogspot.com



[quoted text, click to view]
Re: Help - SQL Jens
3/23/2006 12:13:58 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
---
Help - SQL Luiz Horacio
3/23/2006 1:07:21 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



Re: Help - SQL Luiz Horacio
3/24/2006 10:50:15 PM
Hi Mike,

Thanks a lot.=20

Luiz Horacio
"Mike Hodgson" <e1minst3r@gmail.com> escreveu na mensagem =
news:#txCq$kTGHA.2444@TK2MSFTNGP14.phx.gbl...
Use the CASE predicate like this:

update p1
set p1.value =3D
case
when p2.value_ch =3D '0' then p2.value_re
else p2.value_ch
end
from p1
inner join p2 on p1.exam =3D p2.code

NB/ I changed your SQL-89 join syntax to the more current SQL-92 join =
syntax.

--
mike hodgson
http://sqlnerd.blogspot.com=20



Luiz Horacio wrote:=20
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 =3D p2.value_ch
Where p1.exam =3D p2.code

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

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

Thanks,


Luiz Horacio




Re: Help - SQL Luiz Horacio
3/24/2006 10:50:58 PM
Hi Jens,

Thanks a lot. I have tried some 'case', but with the wrong syntax, so...

Luiz Horacio


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

AddThis Social Bookmark Button