jump to navigation

Ejemplo Update e Insert Masivo September 3, 2012

Posted by juanpablo1manrique in SQL SERVER 2008.
Tags:
trackback

El códgio dice más que mil palabras

Update dbo.RRHH
  SET JefeDirectoTelefono = R2.Telefono,
  JefeDiretoNombre = R2.Nombres + ‘ ‘ + R2.Apellidos  
  from dbo.RRHH
  INNER JOIN dbo.RRHH R2
  ON dbo.RRHH.JefeDirecto = R2.UserName

–Actualizar datos en tabla de verdad
UPDATE FactBroadBand
SET FactBroadBand.TotalMonth = Temp.TotalMonth
FROM #Carrusel Temp
WHERE   FactBroadBand.SourceKey = Temp.SourceKey AND
FactBroadBand.TimeKey = Temp.TimeKey AND
FactBroadBand.UnitKey = Temp.UnitKey AND
FactBroadBand.BroadBandKey = Temp.BroadBandKey

–Insertar datos en tabla de verdad
INSERT INTO  dbo.FactMonthBalance (TimeKey,BalanceCategoryKey,SourceKey,UnitKey,TotalMonth)
SELECT
Temp.TimeKey,Temp.BalanceCategoryKey,

Temp.SourceKey,Temp.UnitKey,Temp.TotalMonth
FROM #TempFactBalance Temp
LEFT JOIN  FactMonthBalance Fact
ON Fact.TimeKey = Temp.TimeKey
AND  Fact.BalanceCategoryKey = Temp.BalanceCategoryKey
AND  Fact.SourceKey = Temp.SourceKey
AND  Fact.UnitKey = Temp.UnitKey
WHERE Fact.BalanceCategoryKey is null

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: