Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Updating a Table using another Table

Author  Topic 

probole
Starting Member

3 Posts

Posted - 2006-12-28 : 18:54:16


I'm trying to update Field4 and Field5 of a TableToUpdate when some fields of Table_Guide are responding to a logic x
Table_Guide has Field1 and Field2 as primary key an so has TableToUpdate

I made the following ActiveX in the DTS transformation between
DTSsource and DTS destination

Functin Main()


'Pao: LA LOGICA DELLA TRASFORMAZIONE
if (DTSSource("PTF")) > "0" THEN
IF (DTSSource("SEGMENTO")) > "0" THEN
DTSDestination("CAMPO_N1") = DTSSource("SEGMENTO")
DTSDestination("PTF_CLIENTE_OLD") = DTSSource("PTF")
ELSE
if (DTSSource("SEGMENTO")) = "0" THEN
DTSDestination("CAMPO_N1") = DSDestination("SEGMENTO_CLIENTE")
DTSDestination("PTF_CLIENTE_OLD") = DTSSource("PTF")
ELSE msgbox "errore: segmento non valido, da sviluppare(inserisci il record scartato in una Tabella_Scartati)"
END IF
END IF
ELSE
IF (DTSSource("PTF")) = "0" THEN
IF (DTSSource("SEGMENTO")) > "0" THEN
DTSDestination("CAMPO_N1") = DTSSource("SEGMENTO")
DTSDestination("PTF_CLIENTE_OLD") = "0"
ELSE
if (DTSSource("SEGMENTO")) = "0" THEN
DTSDestination("CAMPO_N1") = TSDestination("SEGMENTO_CLIENTE")
DTSDestination("PTF_CLIENTE_OLD") = DTSDestination("PTF_CLIENTE_OLD")
ELSE msgbox "errore: segmento non valido, da sviluppare(inserisci il record scartato in una Tabella_Scartati) "
END IF
END IF
ELSE
msgbox "errore: PTF non valido, da sviluppare(inserisci il record scartato in una Tabella_Scartati) "
END IF
END IF
'END IF

'Main = DTSTaskExecResult_Success
Main = DTSTransformStat_OK
End Function

-----------

It works without errors but don't update. It simply add as much rows as Table_Guide

How can I do?

Alternatively, I try to write an update query but it seems I can't refer to Table_Guide in the -----update instruction...

Help!

Thank you.





madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-12-31 : 23:47:24
General Approach

Update T
set col1=S.col1, col2=S.col2,...
from TargetTable T inner join SourceTable S
on T.keycol=S.keycol

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -