0

I have a table in the same format as the source table and want to only insert all rows if the records don't exist.

I would like to only insert records from #Topturn that that do not exist in the table bireports.dbo.topturn.

I tried IF NOT EXIST SELECT * FROM #TOPTURN but that does not insert records at all.

See code below:

INSERT INTO bireports.dbo.TopTurn
(
    ProductionDate,
    Press,
    SKU,
    Shift,
    SpecCureTime,
    CycleTIme,
    TiresProduced,
    MaxTiresPerShift,
    MinutesIntoShift,
    MaxTiresIntoShift,
    OperatorEfficiency,
     TopTurn,
    MolderID,
    Name
)
SELECT tp.productionday,
       tp.press,
       tp.sku,
       tp.shift,
       tp.SpecCureTime,
       tp.CycleTime,
       tp.TiresProduced,
       tp.Maxtirespershift,
       tp.MinutesIntoShift,
       tp.maxTiresIntoShift,
       tp.OperatorEfficiency,
       tp.TopTurn,
       m.MolderID,
       m.Name
   FROM dbo.Molder m
   INNER JOIN #TopTurn tp
   INNER JOIN dbo.Asset a ON tp.press = a.Name
   INNER JOIN dbo.PressLogins pl ON a.ID = pl.AssetID 
                                 AND tp.productionday = pl.ProductionDay
                                 AND tp.shift = pl.Shift
         ON m.MolderID = pl.MolderID
   WHERE tp.productionday = CONVERT(DATE, GETDATE(), 101) 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

0 Answers0