Copy Code code as follows:
INSERT into #DirtyOldWIPBOM SELECT 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))
This will be successful.
Copy Code code as follows:
But select top (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))
will prompt for the error "There is already a object named ' #DirtyOldWIPBOM ' in the ' database"
Why?
[Notes]: Do not use cursors, temporary tables and table variables to replace the cursor will greatly improve performance, today with the cursor processing 700 rows of data in 2 hours, with a temporary table less than 1 seconds to fix.