Import unprocessed rows only

  • Hi,

    I have a staging table named A and a main table named MainTable. I need to import the unprocessed rows from the staging to the main table.

    Below is the a sample Table A

    CREATE TABLE [dbo].[Files](

    [CMD_File_ID] [bigint] IDENTITY(1,1) NOT NULL,

    [CMD_File_Name] [varchar](255) NOT NULL,

    [CMD_File_Date_Loaded] [datetime] NOT NULL)

    CREATE TABLE [dbo].[A](

    [A_ID] [bigint] IDENTITY(1,1) NOT NULL,

    [File_ID] [bigint] NOT NULL,

    [Has_Errors] [bit] NOT NULL,

    [Entity_Name] [varchar](100) NULL,

    [Entity_TIN] [varchar](50) NULL,

    [Entity_NPI] [varchar](10) NULL

    )

    CREATE TABLE [dbo].[MainTable](

    [Staging_Entity_ID] [bigint] IDENTITY(1,1) NOT NULL,

    [File_ID] [bigint] NOT NULL,

    [Has_Errors] [bit] NOT NULL,

    [Entity_Name] [varchar](100) NULL,

    [Entity_TIN] [varchar](50) NULL,

    [Entity_NPI] [varchar](10) NULL

    )

    How do I do that ?

  • How do you detect whether or not a row from staging has been "processed"?

    What is table [dbo].[Files] for? You haven't mentioned it in your dialogue.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Also, how do you import rows now? What is used to "process" a row?

    Show some code, and we'll help. However we are not here to do the work for you.

  • Might I suggest that you examine the MERGE statement. You can start here:

    http://technet.microsoft.com/en-us/library/cc879317.aspx

    And then if you have difficulties, repost including sample data, desired results, and the T-SQL statement(s) you have developed.

    If everything seems to be going well, you have obviously overlooked something.

    Ron

    Please help us, help you -before posting a question please read[/url]
    Before posting a performance problem please read[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

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