Giving dynamic sheet name while importing data from Excel in OPENROWSET query

I want to import data from Excel to table in SQL server. Sheets in Excel file can have any name. I want to get data from first sheet of the excel file. 
CREATE PROC CopyExcelDataToTempTable
@ExcelPath VARCHAR(1000)
AS
BEGIN
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
EXEC sp_configure 'ad hoc distributed queries', 1;
RECONFIGURE;
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1;
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1;
INSERT INTO TempData
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
SELECT CONCAT('Excel 12.0 Xml;HDR=YES;Database=', @ExcelPath),
'SELECT * FROM [Sheet1$]');
END;
Currently I am giving Sheet1 as static name in Select statement. But my sheet name is not fixed. I want to create a dynamic query. If getting Sheet name is not possible then can we put sheet with its index in Select query? There is no front end. Whatever I
want to do is in SQL server 2012. Is there any solution for this problem?

Hi Ajinkya,
To get the sheet names from an excel, you can use the Stored Procedure
SP_TABLES_EX. See the below code.
EXEC sp_addlinkedserver 'ExcelSource', '',
'Microsoft.ACE.OLEDB.12.0',
'c:\worksheet.xls',
NULL,
'Excel 8.0'
EXEC sp_addlinkedsrvlogin 'ExcelSource', 'false'
GO
EXECUTE SP_TABLES_EX 'ExcelSource'
the names in the worksheet.xls and execute result are like below.
Table name
a
b
c
d
Regarding your description, you need the first sheet of your excel. As the result shows, the sheet names are sorted, so there’s no guarantee to get the first one. The SP can work as a workaround when there’s only one sheet in your excel or the required sheet’s
name is customized to be sorted at the top first.
If you have any question, feel free to let me know.
Best regards,
Eric Zhang

Similar Messages

  • Error while importing data from excel to forms

    Hi,
    I am working on Oracle forms 10g, and I'm supposed to import data from excel sheet to forms.
    While the user enters the data,sometimes after entering a particular word he/she hits the alt+enter button.
    As a result the data appears in two lines in a single row
    So,when I try to import the data it's not importing the data in a right manner.
    S0,I want to replace this linefeed and carry with five spaces.
    Eg:The user instead of entering Geekpedia enters Geek
    pedia
    in the excel sheet.
    Now when I import this in the forms I want it to be imported as Geek Pedia.(5 spaces between Geek and pedia).

    Maybe you can consider save excel as .csv files and then you can load them as flatfiles to external table in OWB.

  • How to specify the sheet name while writing data into excel

    _Workbook workbook = (_Workbook)(excelapp.Workbooks.Open(@"E:\ScriptTest\c.xlsx"));
    workbook.Sheets.Add();
    _Worksheet worksheet = (_Worksheet)workbook.ActiveSheet;
    Line 1 Selection of excel sheet
    Line 2:I am intersted in Adding the new sheet
    Line3:Selection of Sheet
    I want to select may be sheet 2 or sheet 3 like that
    How to specify ?
    And instead of just Add() can we specify name of sheet to be created also If yes how ?

    Hi,
    Please try the sample code:
    Dim aSheet As Worksheet
    Set aSheet = Worksheets.Add()
    aSheet.Name = "myWorksheet"
    Worksheets("myWorksheet").Activate
    http://msdn.microsoft.com/en-us/library/office/ff821537(v=office.15).aspx
    PS:
    This forum is for general questions and feedback related to Microsoft Excel, if you have more Excel develop issue, I recommend you post to MSDN forum
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=exceldev&filter=alltypes&sort=lastpostdesc
    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • SSIS 2012 is intermittently failing with below "Invalid date format" while importing data from a source table into a Destination table with same exact schema.

    We migrated Packages from SSIS 2008 to 2012. The Package is working fine in all the environments except in one of our environment.
    SSIS 2012 is intermittently failing with below error while importing data from a source table into a Destination table with same exact schema.
    Error: 2014-01-28 15:52:05.19
       Code: 0x80004005
       Source: xxxxxxxx SSIS.Pipeline
       Description: Unspecified error
    End Error
    Error: 2014-01-28 15:52:05.19
       Code: 0xC0202009
       Source: Process xxxxxx Load TableName [48]
       Description: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
    An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "Invalid date format".
    End Error
    Error: 2014-01-28 15:52:05.19
       Code: 0xC020901C
       Source: Process xxxxxxxx Load TableName [48]
       Description: There was an error with Load TableName.Inputs[OLE DB Destination Input].Columns[Updated] on Load TableName.Inputs[OLE DB Destination Input]. The column status returned was: "Conversion failed because the data value overflowed
    the specified type.".
    End Error
    But when we reorder the column in "Updated" in Destination table, the package is importing data successfully.
    This looks like bug to me, Any suggestion?

    Hi Mohideen,
    Based on my research, the issue might be related to one of the following factors:
    Memory pressure. Check there is a memory challenge when the issue occurs. In addition, if the package runs in 32-bit runtime on the specific server, use the 64-bit runtime instead.
    A known issue with SQL Native Client. As a workaround, use .NET data provider instead of SNAC.
    Hope this helps.
    Regards,
    Mike Yin
    If you have any feedback on our support, please click
    here
    Mike Yin
    TechNet Community Support

  • Import data from excel/csv file in web dynpro

    Hi All,
    I need to populate a WD table by first importing a excel/CSV file thru web dynpro screen and then reading thru the file.Am using FileUpload element from NW04s.
    How can I read/import data from excel / csv file in web dynpro table context?
    Any help is appreciated.
    Thanks a lot
    Aakash

    Hi,
    Here are the basic steps needed to read data from excel spreadsheet using the Java Excel API(jExcel API).
    jExcel API can read a spreadsheet from a file stored on the local file system or from some input stream, ideally the following should be the steps while reading:
    Create a workbook from a file on the local file system, as illustrated in the following code fragment:
              import java.io.File;
              import java.util.Date;
              import jxl.*;
             Workbook workbook = Workbook.getWorkbook(new File("test.xls"));
    On getting access to the worksheet, once can use the following code piece to access  individual sheets. These are zero indexed - the first sheet being 0, the  second sheet being 1, and so on. (You can also use the API to retrieve a sheet by name).
              Sheet sheet = workbook.getSheet(0);
    After getting the sheet, you can retrieve the cell's contents as a string by using the convenience method getContents(). In the example code below, A1 is a text cell, B2 is numerical value and C2 is a date. The contents of these cells may be accessed as follows
    Cell a1 = sheet.getCell(0,0);
    Cell b2 = sheet.getCell(1,1);
    Cell c2 = sheet.getCell(2,1);
    String a1 = a1.getContents();
    String b2 = b2.getContents();
    String c2 = c2.getContents();
    // perform operations on strings
    However in case we need to access the cell's contents as the exact data type ie. as a numerical value or as a date, then the retrieved Cell must be cast to the correct type and the appropriate methods called. The code piece given below illustrates how JExcelApi may be used to retrieve a genuine java double and java.util.Date object from an Excel spreadsheet. For completeness the label is also cast to it's correct type. The code snippet also illustrates how to verify that cell is of the expected type - this can be useful when performing validations on the spreadsheet for presence of correct datatypes in the spreadsheet.
      String a1 = null;
      Double b2 = 0;
      Date c2 = null;
                        Cell a1 = sheet.getCell(0,0);
                        Cell b2 = sheet.getCell(1,1);
                        Cell c2 = sheet.getCell(2,1);
                        if (a1.getType() == CellType.LABEL)
                           LabelCell lc = (LabelCell) a1;
                           stringa1 = lc.getString();
                         if (b2.getType() == CellType.NUMBER)
                           NumberCell nc = (NumberCell) b2;
                           numberb2 = nc.getValue();
                          if (c2.getType() == CellType.DATE)
                            DateCell dc = (DateCell) c2;
                            datec2 = dc.getDate();
                           // operate on dates and doubles
    It is recommended to, use the close()  method (as in the code piece below)   when you are done with processing all the cells.This frees up any allocated memory used when reading spreadsheets and is particularly important when reading large spreadsheets.              
              // Finished - close the workbook and free up memory
              workbook.close();
    The API class files are availble in the 'jxl.jar', which is available for download.
    Regards
    Raghu

  • Is there a way to import data from excel -when one of the columns in excel is hyperlink column?

     Is there a way to import data from excel  - so if a column is hyperlink - the whole data will move to the list (text + link of the hyperlink column)?
    keren tsur

    Hi,
    According to your description, you want to export excel which contains a hyperlink column to SharePoint list.
    Refer to the following steps:
    Open the Excel, insert/create the table. 
    Now click on any cell of table and go to the ‘Design Tools’.
    Click on the Export and then ‘Export table to SharePoint List’.
    You will see a popup where you need to provide the URL of SharePoint site, list name and description.
    Then click on next, On the next screen you will see columns with data types which are going to create in SharePoint list.
    Now click finish and wait until the operation gets finished. You will see that list gets created in SharePoint site with the records.
    Here are two links, you can use as a reference:
    http://sharepointrhapsody.com/2013/03/25/how-to-create-a-connected-excel-file-to-sharepoint-list/
    http://social.technet.microsoft.com/wiki/contents/articles/18705.sharepoint-2013-how-to-export-excel-sheet-to-sharepoint-list.aspx
    Best Regards,
    Lisa Chen
    Lisa Chen
    TechNet Community Support

  • Importing data from Excel

    Hi, I'm trying to import data from Excel into Indesign while still keeping the formatting when updates are made to the linked Excel spreadsheet. However, everytime I update the link, the Indesign document loses all the formatting that I'm worked on and reverts back to the default font / layout. Anyone know a way to keep the formatting and just update the data in Indesign? Thanks.

    Is it possible to save text alignment in certain columns in table / cell style sheets? For example I have 3 columns in a table where'd I'd like to always always have the data in the centre.

  • How to import data from excel or csv files to Oracle table

    hello everybody,
    I am new here and new in Oracle. I would like to know the steps how to import data from excel or csv files to Oracle table.
    Let say I already have table inside the Oracle. Then my user give me the sets of data inside the Excel Worksheet.
    So, how can I import the excel data into Oracle table.
    Thank you in advance.
    cheers,
    shima

    Even easier. Download JDeveloper 11G from this site.
    Set up the database connection, right click on the table, select Import->Excel and specify your file to load it. On the import pop-up, you must view and update each tab indicating Columns, Data Types, and DML.
    Columns -- move the selected columns that you want to load to the box on the right
    Data Types -- select column name from second column to which the data for each column of the import file should load
    DML -- click this tab to generate the INSERT SQL
    Once done click 'Insert'

  • Import data from excel explanation

    Running SAP B1 2007 A PL49.
    In the import data from excel functionality, using items.  There are 2 checkboxes that appear:
    update existing records
    update accounts in existing items
    can anyone explain what each checkbox means?
    Thanks,
    Rich

    hi Rich,
    Update Existing Records
    The system overwrites the data in the corresponding fields of the existing master records.
    The numbers of the master records for business partners or items cannot be overwritten.
    The type of a business partner cannot be changed once business transactions have been entered for that partner.
    Update Accts in Existing Items
    When importing item data, you can also update the information for the expense and revenue accounts.
    To overwrite the respective item master data record
    regards,
    Fidel

  • Import data from excel

    Hi, I am using Jdeveloper 11g 11.1.1.5.0 and I want to import data from excel in my table through the jsf page and commit it to database. How can I implement it. Its urgent please help me!!!!!!!!!!!!!!!!!!!!!

    Unless you are importing Excel data to save a dying patient in the operating theatre, it's not, by definition, urgent!!!!!!!!!!!!!!!!!!!!!! (and I must be right, because I used 22 exclamation points, where you only used 21).
    Have you looked at ADF Desktop Integration to see if that would work for you? If not, you could:
    1). Use an af:inputFile to upload the Excel file
    2). Using something like Apache POI to read the file
    3). Create rows, set the attributes, insert them, and commit them (if you're using ADF BC, you'd use a View Object to do this)
    John

  • Import data from excel file

    Hello.
    Is anybody can help how to import data from excel file to the form created with designer 7.0. Originally there is a script inside the form to populate drop down list and depending from data selected in the ID number drop down list, there will be filled out the description and the prices text fields. But now I have to modify this form with data from excel file, which has more than 30000 lines and put all this data to script is too much.
    So, can somebody know how can I after filling the ID number field , populate the description and price text fields with data from excel file corresponding to this ID number ?
    This form is used in Adobe reader.
    Any comments are welcome.
    Regards,
    Aivar

    Hi
    That's what i said in my prev. Post to clear cache... :)
    disable your cache from nqsconfig.ini
    In cache section of NQSConfig file,
    you find
    ENABLE     =     YES;
    set to NO
    OR
    if you are using data ware house as the source for OBIEE,
    you know that when ETL is done, so just create iBot to purge cache automatically at that particular intervals,
    So that report runs freshly at that time
    And what happened to your View Selector question?
    Edited by: Kishore Guggilla on Jul 3, 2009 3:52 PM

  • Import data from excel file - best practice in the CQ?

    Hi,
    I have question related to importing data from excel file and creates from those data a table in the CQ page. Is inside CQ some OOTB component which provides this kind of functionalities? Maybe somebody implement this kind of functionality or there is best practice to do this kind of functionalities?
    Thanks in advance for any answer,
    Regards
    kasq

    You can check a working example package [1] (use your Adobe ID to log in)
    After installing it, go to [2] for immediate example.
    Unfortunately it only supports the old OLE-2 Excel format (.xls and not .xlsx)
    [1] - http://dev.day.com/content/packageshare/packages/public/day/cq540/demo/xlstable.html
    [2] - http://localhost:4502/cf#/content/geometrixx/en/company/news/pressreleases/my_personal_bes ts.html

  • Import data from excel 2013 workbook issue,is it a bug ?

    When I use powerquery to import data from excel 2013 workbook An unexpected error occurred.Other editions no problem.

    I‘m sure this is a bug.I'm option in default language set to English.Saved the file and use powerquery import it.Excle worked fine.
    I'm option in default language set to simple chinese.Saved the file and use powerquery import it.An error occurred.

  • Importing data from Excel using SDK!

    Hi All,
    Can we do a Goods Receipt and Goods Issue via SDK.
    IF so any code available for the same!Secondly can we
    Import data from Excel using SDK!
    Thnx in advance

    Hi Vinayak
    4 your 2nd issue: you can easily use Excel.Application COM-object. In C# exporting from Excel can be:
    Excel.Application     oXL;
    Excel._Workbook     oWB;
    Excel._Worksheet     oSheet;
    string          strTemplatePath;
    strTemplatePath = Application.StartupPath + "WHRequestList.xlt";
    try
         oXL = new Excel.Application();
         oWB     = (Excel._Workbook)(oXL.Workbooks.Add(strTemplatePath));
         oSheet     = (Excel._Worksheet)oWB.ActiveSheet;
         SAPbouiCOM.Item     edDocNum;
         SAPbouiCOM.IEditText specEdDocNum;
         edDocNum = SBOApp.Forms.Item(FormUID).Items.Item("8");
         specEdDocNum = (SAPbouiCOM.IEditText)edDocNum.Specific;
         SAPbouiCOM.Item     edDocDate;
         SAPbouiCOM.IEditText specEdDocDate;
         edDocDate = SBOApp.Forms.Item(FormUID).Items.Item("10");
         specEdDocDate = (SAPbouiCOM.IEditText)edDocDate.Specific;
         oSheet.Cells[2, "F"] = "¹ " + specEdDocNum.String + " îò " + specEdDocDate.String;
         oXL.Visible = true;
         oXL.UserControl = true;
    BTW, don't forget to add Excel object in ProjectReferences
    For sure, importing  (reading) from Excel is the same
    HTH

  • Importing data from excel  ... when clicking finish button nothing happens

    Version 3.1/32bit version ... I am trying to import data from excel but when i clicki finish button nothing happens. any idea. this used to work fine on the older version?

    Hi,
    Generally speaking, the data import from an xls or xlsx format Excel file works. You need to provide more information about your environment and the Excel file itself -- size, data types of the columns, number of worksheets, etc.
    I recommend running sqldeveloper.exe (not sqldeveloperW.exe) from a command line window. Repeat your import test and see if any stack trace appears in the console. For example, trying to open a 0 byte xls file results in a stack trace like this:
    java.lang.NullPointerException
            at oracle.dbtools.raptor.data.readers.XLSReader.openFile(XLSReader.java: 524)
    ...Regards,
    Gary
    SQL Developer Team

Maybe you are looking for

  • Is it possible to see the timestamp from the camera in my timeline?

    I have been given notes to look out for certain things according to the time on the camera from when the clip was recorded. I can see the start and end times for my clips where I import the media clips. I can also see the camera time ticking up when

  • Itunes has encountered a problem & needs to close - HELP!

    Hi lovely people. Please help me. My iTunes just won't work. It won't open & when I click it the following appears: *iTunes has encountered a problem and needs to close. We are sorry for the inconvenience.* Data contained in the error report is: *App

  • Everytime I start Pages it opens old documents

    When I start Pages, older documents are opened automatically.  I have unchecked "Restore Windows when Quitting and re-opening apps" and yet, everytime I open windows, it opens the last couple things I've been working on.  How can I stop this?

  • HELP wont install 1.2software version geting an unkown error ocued(1417)???

    ok people i installed the 7 itunes version for my30GB video pod but now that i connect my ipod it wont do anything it wont update the songs i have on the music library says do i want to instal the 1.2 software version to my ipod i said yes now it say

  • [Solved] Prelink compilation error

    gcc -Wall -Wno-pointer-sign -march=native -O2 -pipe -fomit-frame-pointer -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -Wl,-z -Wl,relro -o execstack execstack.o checksum.o data.o dso.o dwarf2.o fptr.o hashtab.o mdebug.o stabs.o crc32.o arch-i386.o arch-a