Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2004
    Location
    Alpine Califormia
    Posts
    1,789

    Unanswered: Insert procedure from Excel

    Hi all

    I need to create a stored procedure that will insert from an Excel document. And I'm not exaclty sure of how to do that.


    Code:
    CREATE PROCEDURE [Insert_ActiveSuspensions]
    	
    AS 
    INSERT INTO [GamingCommissiondb].[dbo].[License_SuspensionsView] 
    	 ([TM #],
    	 [FIRSTNAME],
    	 [LASTNAME],
    	 [SS #],
    	 [REASONFORSUSPENSION],
    	 [ENDDATE]
             [BEGINDATE]) 
    	 
     
    SELECT	 
    	 [TM#],
    	 [LASTNAME],
    	 [FIRSTNAME],
    	 [SSN#],
    	 [NOTES],
    	 [DATEOFCONDITIONAL]
    
    FROM "C:\Documents and Settings\Desiree Stevenson\My Documents\TerminationInserts.xls"
    IF @@Error <> '0'

    is this correct??

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    create a linked server to the excel file. look up sp_addlinkedserver in BOL.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Feb 2004
    Location
    Alpine Califormia
    Posts
    1,789

    Ok

    I am wanting to export from a table to an Excel spreadsheet and then to a table in another database.

    I should explained that better sorry

  4. #4
    Join Date
    Mar 2005
    Location
    Netherlands
    Posts
    280
    Consider the import/export wizard in Enterprise Manager (SQL 2000) or Management Studio (SQL 2005).

  5. #5
    Join Date
    May 2004
    Location
    bangalore
    Posts
    270
    Try with BCP command........... Google "BCP"............ There is your answer.........



    Thanks,
    Rahul Jha

  6. #6
    Join Date
    Jun 2004
    Location
    Long Island
    Posts
    696
    With Excel, make sure SET NOCOUNT ON is specified in the procedure. It causes problems called by an xla.

  7. #7
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by DBA_Rahul
    Try with BCP command........... Google "BCP"............ There is your answer.........



    Thanks,
    Rahul Jha

    excuse me?

    this message...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  8. #8
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Quote Originally Posted by desireemm
    I am wanting to export from a table to an Excel spreadsheet and then to a table in another database.

    I should explained that better sorry
    ummm, why?

    is the database on the same server/instance?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

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