Results 1 to 5 of 5

Thread: Importing Data

  1. #1
    Join Date
    Apr 2009
    Posts
    3

    Unanswered: Importing Data

    hello everyone!
    I have to import records from excel sheet into sql table which has already records..now please somebody guide me on this (step by step) I am new in SQL server...

  2. #2
    Join Date
    Nov 2004
    Location
    Canada
    Posts
    58
    You could import all of the records from excel into a staging table then write a simple insert script where not exists.

    Or create an ssis package to import the excel file into the table directly where not exists.

    If you are not familar with SQL I would recommend the first method.

    Launch studio manager, right click on the database select task import data
    use excel as your connection and find your spreadsheet. Import into a staging table. (sheet1 is usally the default) execute.
    Then use query analyzer to write an insert script where the records do not exist. you will need to know the primary key of the existing data.


    Look up examples of "where not exists"

  3. #3
    Join Date
    Apr 2009
    Posts
    3
    Hmm I am going with Importing wizard but I dont know "where not exits" I have used simple insert statement
    INSERT INTO ASICActivity (ID,Code,Name,,SectorID,TypeID,SubNDPCode)
    VALUES (ID,Code,Name,,SectorID,TypeID,SubndpCode)...Can you Please edite this for mee

  4. #4
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    You must first import the data to a staging table, then use that staging table as data source to populate the "real" table.
    Code:
    INSERT INTO ASICActivity (ID, Code, Name, SectorID, ...)
    SELECT ID, Code, Name, SectorID, ...
    FROM ASICActivityStaging
    WHERE NOT EXISTS (SELECT 1 
                      FROM ASICActivity as A
                      WHERE A.ID = ASICActivityStaging.ID
                      )
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  5. #5
    Join Date
    Dec 2008
    Posts
    135

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •