Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2010
    Posts
    20

    Unanswered: Exporting data from a table in SQL Server to Excel...

    Hi!

    I don't know how to export my table data from SQL Server to an Excel-file...



    I have a table: "HenkTunnit" in a database: "DB_Hallintaa"
    (If needed) The connection string is:
    Data Source=WL100701\SQLEXPRESS;Initial Catalog=DB_Hallintaa;Integrated Security=True

    I also have an Excel-file named "testing.xls" in C:\

    So, I want to insert the rows: [Pvm.],[TyöNro],[ProjeHenkID] from my table "HenkTunnit" to my Excel-file's page "testing.xls" "Taul1"





    Code:
    INSERT INTO OPENROWSET('Microsoft.Jet.OLEDB.4.0', 
        'Excel 8.0;Database=C:\testing.xls;', 
        'SELECT * FROM [Taul1]') SELECT * FROM HenkTunnit

    I tried the above SQL code, but got an error:
    "
    OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" returned message "The Microsoft Jet database engine could not find the object 'Taul1'. Make sure the object exists and that you spell its name and the path name correctly.".
    Msg 7350, Level 16, State 2, Line 1
    Cannot get the column information from OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

    "

  2. #2
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Is [Taul1] defined as a table (formatted as a table) in your testing.xls, or it's a tab name? If the latter, - try [Taul1$].
    "The data in a record depends on the Key to the record, the Whole Key, and
    nothing but the Key, so help me Codd."

  3. #3
    Join Date
    Nov 2010
    Posts
    20
    Quote Originally Posted by rdjabarov View Post
    Is [Taul1] defined as a table (formatted as a table) in your testing.xls, or it's a tab name? If the latter, - try [Taul1$].

    Ok, I did that, but now the error reads:
    Msg 213, Level 16, State 1, Line 1
    Column name or number of supplied values does not match table definition.



    ....

  4. #4
    Join Date
    Aug 2004
    Location
    Dallas, Texas
    Posts
    831
    Probably because C:\testing.xls already has columns and they do not match the selected columns. Try deleting existing C:\testing.xls file first.

Tags for this Thread

Posting Permissions

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