Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8241595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:53:01+00:00 2026-06-07T20:53:01+00:00

I am writing a stored procedure that merges two tables with identical schema from

  • 0

I am writing a stored procedure that merges two tables with identical schema from two databases. I searched for an answer and thought it might be a permission issue, but I cannot resolve the problem.

Here is the error message:

Msg 208, Level 16, State 1, Procedure spMergeDefects, Line 66
Invalid object name

Here is the stored procedure code:

DECLARE @MergeOutput TABLE
(
ActionType  nvarchar(10),
del_guidDefectID    uniqueidentifier,
del_idintDefectID   int,
del_fkintStructureID    int,
del_fkintDefectTypeID   int,
del_tinSeverityCode tinyint,
del_intCreatedBy    int,
del_dtmDateInspected    datetime,
del_bitRepaired bit,
del_dtmRepaired datetime,
del_intRepairedBy   int,
del_tintDefectStatus    tinyint,
del_strRepairWorkOrder  varchar(20),
del_bitTempRepaired bit,
del_dtmTempRepaired datetime,
del_intModifiedBy   int,
del_dtmModified datetime,   
del_bitCircuitSpecific  bit,
del_strCircuit  varchar(20),
del_strUser1    varchar(50),
del_strUser2    varchar(50),
del_intNADefectLodID    int,
del_fkstrInspectionCycleID  varchar(10),
del_strNote varchar(255),
del_SpanDirection   varchar(10),
del_Distance    int,
del_Deleted bit,
ins_guidDefectID    uniqueidentifier,
ins_idintDefectID   int,
ins_fkintStructureID    int,
ins_fkintDefectTypeID   int,
ins_tinSeverityCode tinyint,
ins_intCreatedBy    int,
ins_dtmDateInspected    datetime,
ins_bitRepaired bit,
ins_dtmRepaired datetime,
ins_intRepairedBy   int,
ins_tintDefectStatus    tinyint,
ins_strRepairWorkOrder  varchar(20),
ins_bitTempRepaired bit,
ins_dtmTempRepaired datetime,
ins_intModifiedBy   int,
ins_dtmModified datetime,   
ins_bitCircuitSpecific  bit,
ins_strCircuit  varchar(20),
ins_strUser1    varchar(50),
ins_strUser2    varchar(50),
ins_intNADefectLodID    int,
ins_fkstrInspectionCycleID  varchar(10),
ins_strNote varchar(255),
ins_SpanDirection   varchar(10),
ins_Distance    int,
ins_Deleted bit

);

MERGE [tblMM-Defects] AS tgt
USING dbo.NGFIElecMobile.[tblMM-Defects] AS src
ON tgt.guidDefectID = src.guidDefectID
WHEN MATCHED THEN
    UPDATE SET 
    tgt.fkintStructureID = src.fkintStructureID,
    tgt.fkintDefectTypeID = src.fkintDefectTypeID,
    tgt.tinSeverityCode = src.tinSeverityCode,
    tgt.intCreatedBy = src.intCreatedBy,
    tgt.dtmDateInspected = src.dtmDateInspected,
    tgt.bitRepaired = src.bitRepaired,
    tgt.dtmRepaired = src.dtmRepaired,
    tgt.intRepairedBy = src.intRepairedBy,
    tgt.tintDefectStatus = src.tintDefectStatus,
    tgt.strRepairWorkOrder = src.strRepairWorkOrder,
    tgt.bitTempRepaired = src.bitTempRepaired,
    tgt.intModifiedBy = src.intModifiedBy,
    tgt.dtmModified = src.dtmModified,
    tgt.bitCircuitSpecific = src.bitCircuitSpecific,
    tgt.strCircuit = src.strCircuit,
    tgt.strUser1 = src.strUser1,
    tgt.strUser2 = src.strUser2,
    tgt.fkstrInspectionCycleID = src.fkstrInspectionCycleID,
    tgt.strNote = src.strNote,
    tgt.SpanDirection = src.SpanDirection,
    tgt.Distance = src.Distance

WHEN NOT MATCHED BY TARGET THEN
    INSERT 
    (fkintStructureID,
    fkintDefectTypeID,
    tinSeverityCode,
    intCreatedBy,
    dtmDateInspected,
    bitRepaired,
    dtmRepaired,
    intRepairedBy,
    tintDefectStatus,
    strRepairWorkOrder,
    bitTempRepaired,
    intModifiedBy,
    dtmModified,
    bitCircuitSpecific,
    strCircuit,
    strUser1,
    strUser2,
    fkstrInspectionCycleID,
    strNote,
    SpanDirection,
    Distance)

    VALUES
    (src.fkintStructureID,
    src.fkintDefectTypeID,
    src.tinSeverityCode,
    src.intCreatedBy,
    src.dtmDateInspected,
    src.bitRepaired,
    src.dtmRepaired,
    src.intRepairedBy,
    src.tintDefectStatus,
    src.strRepairWorkOrder,
    src.bitTempRepaired,
    src.intModifiedBy,
    src.dtmModified,
    src.bitCircuitSpecific,
    src.strCircuit,
    src.strUser1,
    src.strUser2,
    src.fkstrInspectionCycleID,
    src.strNote,
    src.SpanDirection,
    src.Distance
    )

    WHEN NOT MATCHED BY SOURCE 
        AND tgt.CheckedOutForInsp = 1 AND CheckOutID = @CheckOutID THEN
    DELETE

    OUTPUT
    $action,
    DELETED.guidDefectID,       
    DELETED.idDefectID, 
    DELETED.fkStructureID,
    DELETED.fkDefectTypeID,     
    DELETED.tinSeverityCode,        
    DELETED.CreatedBy,
    DELETED.dtmDateInspected,
    DELETED.bitRepaired,
    DELETED.dtmRepaired,    
    DELETED.RepairedBy, 
    DELETED.tDefectStatus,
    DELETED.strRepairWorkOrder,
    DELETED.bitTempRepaired,    
    DELETED.dtmTempRepaired,    
    DELETED.ModifiedBy,
    DELETED.dtmModified,        
    DELETED.bitCircuitSpecific,
    DELETED.strCircuit,
    DELETED.strUser1,
    DELETED.strUser2,
    DELETED.NADefectLodID,
    DELETED.fkstrInspectionCycleID,
    DELETED.strNote,    
    DELETED.SpanDirection,
    DELETED.Distance,
    DELETED.[Deleted],
    INSERTED.guidDefectID,      
    INSERTED.idDefectID,    
    INSERTED.fkStructureID,
    INSERTED.fkDefectTypeID,        
    INSERTED.tinSeverityCode,       
    INSERTED.CreatedBy,
    INSERTED.dtmDateInspected,
    INSERTED.bitRepaired,
    INSERTED.dtmRepaired,   
    INSERTED.RepairedBy,    
    INSERTED.tDefectStatus,
    INSERTED.strRepairWorkOrder,
    INSERTED.bitTempRepaired,   
    INSERTED.dtmTempRepaired,   
    INSERTED.ModifiedBy,
    INSERTED.dtmModified,       
    INSERTED.bitCircuitSpecific,
    INSERTED.strCircuit,
    INSERTED.strUser1,
    INSERTED.strUser2,
    INSERTED.NADefectLodID,
    INSERTED.fkstrInspectionCycleID,
    INSERTED.strNote,   
    INSERTED.SpanDirection,
    INSERTED.Distance,
    INSERTED.[Deleted]
    INTO @MergeOutput
    ;

Thanks for your help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:53:03+00:00Added an answer on June 7, 2026 at 8:53 pm

    I’m guessing that your USING dbo.NGFIElecMobile.[tblMM-Defects] AS src line should really be USING NGFIElecMobile.dbo.[tblMM-Defects] AS src

    There may be other problems after that.

    Here is some guidance for proper multipart naming in T-SQL:
    Transact-SQL Syntax Conventions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a stored procedure that should sync a table from our production environment
I am writing a stored procedure that will get results from one table then
I am writing a stored procedure that when completed will be used to scan
I am using SQL Server. I'm writing a stored procedure that executes a series
i am writing stored procedures in MySQL that return values; CREATE PROCEDURE getCustomerById (id
I am writing an install script that installs all tables, stored procedures, views, full
I'm new to this. I'm writing a clr stored procedure that calls another stored
I am writing a stored procedure that works with a heavy select statement. The
I am having trouble writing a stored procedure that first checks a hashed password
I am writing a stored procedure to perform a dynamic search that spans 10+

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.