February 13, 2015 at 1:53 pm
I am trying to import 1 spreadsheet to a database table. I am using SSMS export import wizard to import spreadsheet. My goal is to import whole spreadsheet in one single column , can I do that? Please any help will be greatluy appreciated.
February 13, 2015 at 2:05 pm
Well you could use a little excel magic to concat all the data into one column then import that column.
February 13, 2015 at 2:34 pm
SSMS_2007 (2/13/2015)
I am trying to import 1 spreadsheet to a database table. I am using SSMS export import wizard to import spreadsheet. My goal is to import whole spreadsheet in one single column , can I do that? Please any help will be greatluy appreciated.
I'm not sure you can do that from the import wizard, but it can be done in the dataflow by using a Derived Column transformation to concatenate the columns together.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
February 13, 2015 at 5:56 pm
SSMS_2007 (2/13/2015)
I am trying to import 1 spreadsheet to a database table. I am using SSMS export import wizard to import spreadsheet. My goal is to import whole spreadsheet in one single column , can I do that? Please any help will be greatluy appreciated.
Do you mean that you want to store the whole spreadsheet file .xls file as it is in the operating system?
--Jeff Moden
Change is inevitable... Change for the better is not.
February 14, 2015 at 4:43 am
I am pretty confused by your requirement too. Can you, please, maybe describe the scenario? Otherwise, I would agree with ZZartin on his solution. It could get fairly tedious if there is a lot of columns.
Petr
February 17, 2015 at 4:01 pm
If you're using Excel 2007 or later the workbooks are a collection of xml files under the hood. "In theory" you could import those xml files into a SQL Server column of XML datatype. However you would likely need to use something other than the SSMS import/export wizard.
To go this route you would need to hit these high level steps:
Make a copy of the Excel file you're working with.
Change the file extension to .zip.
Extract the zip contents.
Figure out which xml bits you're interested in.
Import those to SQL Server.
Clean up your copied and extracted zip and xml files.
BIG Disclaimer: The effort of doing this may be more trouble than it's worth. What is it you're trying to achieve by importing a spreadsheet into a single column?
P.S. It's possible that an Excel workbook/spreadsheet could exceed the max size of a single SQL Server XML record.
P.P.S. There may be APIs out there you could use that would eliminate the need to mess with the zip extraction step to access the XML, not sure though, would need additional research.
February 17, 2015 at 5:08 pm
I'm not saying I recommend this or anything, but something like this is likely to work.
DECLARE @ImportedXML TABLE
(
[FileName] NVARCHAR(100)
,Document VARBINARY(MAX)
);
DECLARE @FileName NVARCHAR(200) = 'YourExcelFile.xlsx'
,@SQL NVARCHAR(MAX)
,@SQLParms NVARCHAR(MAX) = N'@FileName NVARCHAR(200)';
SELECT @sql =
N'SELECT @FileName ' + CHAR(10) +
N' ,* FROM OPENROWSET(BULK N''' + @Filename + ''', SINGLE_BLOB) AS Document';
-- Retrieve the file
INSERT INTO @ImportedXML ([FileName], Document)
EXEC sp_executesql @sql, @SQLParms, @Filename=@Filename;
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
February 18, 2015 at 12:29 am
Heh... the OP has left the building! 😛
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply