October 5, 2010 at 8:22 am
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 ?
October 5, 2010 at 8:37 am
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.
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
October 5, 2010 at 8:47 am
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.
October 5, 2010 at 8:53 am
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.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply