![the most unknown worksheet the most unknown worksheet](https://www.ereadingworksheets.com/reading-worksheets/context-clues/context-clues-2-7/preview/context-clues-2-7-01.jpg)
#THE MOST UNKNOWN WORKSHEET CODE#
Great job (and hat's off to you for the embedded comments that make the code crystal clear) and thanks for sharing even years after the original questions was posted. I've had this pinned as a link since you posted it and have been seriously remiss in saying "Thank You". EXEC sp_tables_ex sp_columns_ex Remove temp linked server exec sp_executesql 'SELECT * INTO #MyTempTable FROM OPENROWSET(''SQLNCLI'', ''Server=(local) Trusted_Connection=yes '',''EXEC sp_tables_ex TempExcelSpreadsheet'')' 'EXEC sp_tables_ex TempExcelSpreadsheet') SELECT * INTO #MyTempTable FROM OPENROWSET('SQLNCLI', 'Server=(local) Trusted_Connection=yes ', Return the table info, each worksheet pbb gets its own unique name Grab the current user to use as a remote login ACE 12.0 seems to work for both xsl and xslx, though some might prefer the older JET providerĮxec = 'ACE = 'Excel 12.0 HDR=Yes' If exists(select null from sys.servers where name = begin
![the most unknown worksheet the most unknown worksheet](https://images.twinkl.co.uk/tw1n/image/private/t_630/image_repo/1b/f0/us-t-t-n-2544720-number-bonds-10-20-and-100-ultimate-challenge-activity-sheets-english_ver_2.jpg)
Remove existing linked server (if necessary) IF OBJECT_ID('tempdb.#MyTempTable') IS NOT NULL Get table (worksheet) or column (field) listings from an excel spreadsheetĭECLARE sysname = 'TempExcelSpreadsheet'ĭECLARE nvarchar(1000) = 'D:\\SHARE\\WLAN\\Report.xlsx' However, I was curious whether I could extract the name of the first worksheet in the workbook from within T-SQL. I've created error handling to alert the user of an incorrectly named sheet. And if I pass an invalid worksheet name, the code above will fail. The workbook *should* contain just one worksheet and the worksheet *should* be named identically to the workbook (2011-08 AUG), but it may not be named as such. However, I won't always know the worksheet name. The workbook name will always be known: when the user uploads the file, I change the name to match a certain pattern. I've created a stored procedure that accepts two arguments: the name of an Excel workbook and the name of the first worksheet found in that workbook dynamic SQL, I'm able to construct a statement that pulls out data.