Insert records with a where

  • I want to insert record job allocations only for selected jobs

    I know the following code won't work form the WHERE part but this gives you an idea of what I want achieve.  TIA.

    INSERT INTO dbo.WipJobAllLab(W.Job, Operation, WorkCentre, IExpUnitRunTim, Milestone, IWcRateInd) VALUES(W.Job, 1, '001', 0.01, 'N', 1)
    ...
    "WHERE SELECT W.Job FROM dbo.WipMaster W LEFT JOIN dbo.WipJobAllLab L ON L.Job=W.Job WHERE L.Job IS NULL AND W.Complete<>'Y'"
  • Your post is anything but clear. Bear in mind that I know nothing about your job or what a "job allocation" is.

    But may this is what you want:

    INSERT INTO dbo.WipJobAllLab(W.Job, Operation, WorkCentre, IExpUnitRunTim, Milestone, IWcRateInd) 
    SELECT W.Job, 1, '001', 0.01, 'N', 1
    FROM dbo.WipMaster W
    LEFT JOIN dbo.WipJobAllLab L ON L.Job=W.Job
    WHERE L.Job IS NULL
    AND W.Complete<>'Y'

    If this is not right, please provide CREATE TABLE statements for your tables, INSERT statements with sample data and the desired result given the test data. Please also give a brief explanation of why you want that result. Finally, don't forget to include the output of "SELECT @@version".

    [font="Times New Roman"]Erland Sommarskog, SQL Server MVP, www.sommarskog.se[/font]

  • Yes, this is it.   Thank you.

     

    (sorry for the duplicate thread , the server was not responding on SUBMIT -  I probably clicked twice)

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply