query

  • Is there an alternate way to query this to make it fast.

    insert into dbo.emp_A

    (Column1,Column2,Column3,Column4,Column5)

    Select Column1,Column2,Column3,Column4,Column5

    From dbo.emp_A Where EMP_state = 'PA'

    Except Select Column1,Column2,Column3,Column4,Column5

    From Obbeaver.RevProd.dbo.emp_A

    go

  • If one of those columns is a PK, you could try:

    ;

    WITH CTE AS

    (

    SELECT PK-COLUMN From dbo.emp_A Where EMP_state = 'PA'

    EXCEPT

    SELECT PK-COLUMN From Obbeaver.RevProd.dbo.emp_A

    )

    INSERT INTO dbo.emp_A

    (Column1,Column2,Column3,Column4,Column5)

    Select Column1,Column2,Column3,Column4,Column5

    From dbo.emp_A

    JOIN CTE ON emp_A.PK-COLUMN = CTE.PK-COLUMN;

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

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

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