SQL Server inserts data samples into temporary tables _mssql

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.