Ayuda con un update..

18/05/2005 - 20:34 por MSNNEWS.MICROSOFT.COM | Informe spam
holA todos!!!

me he vuelto un ocho haciendo este update, que inicialmente pensé que no me
iba a dar problema..:


CREATE TABLE #A ( C1 INT PRIMARY KEY , C2 INT , C3 INT )

INSERT INTO #A VALUES ( 1,2,3)
INSERT INTO #A VALUES ( 2,4,5)
INSERT INTO #A VALUES ( 3,6,7)
INSERT INTO #A VALUES ( 4,8,9)


SELECT * FROM #A

/*
NECESITO SUMAR AL lLOS CAMPOS C1 Y C3 DEL REGISTRO C1 = 2 LOS VALORES
RESPECTIVO DEL REGISTRO C1 = 4
deberia quedar

C1 C2 C3
2 12 14 --Sumo los valores respectivos del registro c1= 4


C1 C2 C3
1 2 3
2 4+8 5+9 --Sumo los valores respectivos del registro c14
3 6 7
4 8 9
*/


mil gracias

Eusebio
 

Leer las respuestas

#1 Alejandro Mesa
18/05/2005 - 21:34 | Informe spam
Trata,

update #a
set
c2 = c2 + (select c2 from #a as a where a.c1 = 4),
c3 = c3 + (select c3 from #a as a where a.c1 = 4)
where
c1 = 2


AMB

"MSNNEWS.MICROSOFT.COM" wrote:

holA todos!!!

me he vuelto un ocho haciendo este update, que inicialmente pensé que no me
iba a dar problema..:


CREATE TABLE #A ( C1 INT PRIMARY KEY , C2 INT , C3 INT )

INSERT INTO #A VALUES ( 1,2,3)
INSERT INTO #A VALUES ( 2,4,5)
INSERT INTO #A VALUES ( 3,6,7)
INSERT INTO #A VALUES ( 4,8,9)


SELECT * FROM #A

/*
NECESITO SUMAR AL lLOS CAMPOS C1 Y C3 DEL REGISTRO C1 = 2 LOS VALORES
RESPECTIVO DEL REGISTRO C1 = 4
deberia quedar

C1 C2 C3
2 12 14 --Sumo los valores respectivos del registro c1= 4


C1 C2 C3
1 2 3
2 4+8 5+9 --Sumo los valores respectivos del registro c1> 4
3 6 7
4 8 9
*/


mil gracias

Eusebio





Preguntas similares