How to insert records based on Audit Table

  • Audit table:

    CREATE TABLE [dbo].[AUDIT_RECORD](

    [FILENAME] [varchar](100) NULL,

    [LOAD_DATE] [datetime] NULL

    )

    Insert into [dbo].[AUDIT_RECORD] values('Sample',12/09/2012)

    Insert into [dbo].[AUDIT_RECORD] values('Sample',13/09/2012)

    ----------------------------------------------------

    DB Table:

    CREATE TABLE [dbo].[Sample1](

    [pKey] [int] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,

    [SasId] [nvarchar](max) NULL,

    [Name] [nvarchar](max) NULL,

    [TypeId] [nvarchar](max) NULL,

    [UserName] [nvarchar](max) NULL,

    [SysCreatedDateTime] [datetime] NULL,

    [CompletedDateTime] [datetime] NULL,

    [Boolean] [bit] NULL,

    )

    insert into Sample1 values('sdf','werwer','s233','xzfdsdf',12/11/2011,14/11/2011,'TRUE')

    ----------------------------------------

    Ques:

    Have a table “Sample1” and one of the columns is “SysCreatedDateTime”

    Need to transfer the records from a table(Sample1) to another table(Sample2) based on the below condition

    Condition:

    Sample.SysCreatedDateTime > [dbo].[AUDIT_RECORD].MAX(LOAD_DATE)

    How will we do this using SSIS 2005?

    Regards

    Sql

  • sqlstud (10/5/2012)


    ...

    How will we do this using SSIS 2005?

    Regards

    Sql

    SSIS is a bit overkill for this.

    INSERT INTO ...

    SELECT... FROM ... WHERE ...

    “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

  • you can use execute sql script task and there you write one script of select * into...

  • Thanks Chris and Div

    Regards

    Sqlstud

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

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