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] Luiz Horacio wrote:
>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
>
>
>
>
>
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
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