Copy codeThe Code is as follows:
Insert into # DirtyOldWIPBOM select top (100) PERCENT dbo. WIP_BOM.Model, dbo. WIP_BOM.PartNumber, WIP_BOM.WIP
FROM dbo. WIP_BOM left outer join dbo. BOM_CHINA on ltrim (dbo. WIP_BOM.Model) = LTRIM (dbo. BOM_CHINA.Model) and ltrim (dbo. WIP_BOM.PartNumber) = LTRIM (dbo. BOM_CHINA.PartNumber) AND dbo. WIP_BOM.Qty = dbo. BOM_CHINA.Qty AND BOM_CHINA.WIP =
WIP_BOM.WIP WHERE (dbo. BOM_CHINA.Model is null) and exists (SELECT * FROM dbo. BOM_CHINA where wip = WIP_BOM.WIP and ltrim (Model) = LTRIM (WIP_BOM.Model ))
In this way, you can succeed.
Copy codeThe Code is as follows:
However, select top (100) PERCENT dbo. WIP_BOM.Model, dbo. WIP_BOM.PartNumber, WIP_BOM.WIP into # DirtyOldWIPBOM
FROM dbo. WIP_BOM left outer join dbo. BOM_CHINA on ltrim (dbo. WIP_BOM.Model) = LTRIM (dbo. BOM_CHINA.Model) and ltrim (dbo. WIP_BOM.PartNumber) = LTRIM (dbo. BOM_CHINA.PartNumber) AND dbo. WIP_BOM.Qty = dbo. BOM_CHINA.Qty AND BOM_CHINA.WIP =
WIP_BOM.WIP WHERE (dbo. BOM_CHINA.Model is null) and exists (SELECT * FROM dbo. BOM_CHINA where wip = WIP_BOM.WIP and ltrim (Model) = LTRIM (WIP_BOM.Model ))
Error "There is already an object named '# DirtyOldWIPBOM' in the database" is displayed"
Why?
[Note]: Do not use cursors. Replacing cursors with temporary tables and table variables will greatly improve performance. Today, it takes two hours to process 700 rows of data with cursors, it takes less than 1 second to use a temporary table.