r/SQLServer • u/dumpsterninja • May 13 '22
Excel to Sql Server
I have created a developer utility for getting Excel documents into Sql Server. It's still pre-release, but it's been used in some real life scenarios and has proven useful.
The idea is simply to have a utility that has minimal configuration and can just get data into MSSQL for further evaluation/interrogation without some of the headache I get when using Import Data from Excel in SSMS.
The utility and source are available on GitHub ExcelToSqlServer.
I also created a video which shows one use case and goes over each of the individual configuration options. Excel To Sql Server: a utility to simplify your life
I hope that a few of you find some value in this solution. Maybe even fork the repo as a start to making it super awesome for your own needs.
3
u/JohnSpikeKelly May 13 '22
My biggest headache for excel to sql is that ssms import samples a few rows only then decided a schema that doesn't fit the other rows.
Does yours do that? I.e. Build a table capable of importing all rows.
2
u/dumpsterninja May 13 '22
This import utility does not infer anything about the data types; it brings everything in as nvarchar(Max),that way you can do your own validation and analysis in sql before moving it to whatever tables you want the data in.
Is that what you where asking?
2
u/JohnSpikeKelly May 13 '22
That works for me.
My usual gripe was SSMS Import looks at first 5 rows (I don't know how many it looks at) and says "hey this is a nvarchar(20)" then row 6 has 21 chars and it breaks. Update it's inferred schema, repeat so many times, until it imports.
Your solution is better! Thanks.
2
u/ihaxr 2 May 14 '22
I agree with this, but it's usually not too difficult to figure out the issue... I wish it would just set the text fields to nvarchar(4000) at a minimum... then if it truncates it you can manually set the field to nvarchar(max).
2
u/ComicOzzy May 14 '22
And it's limited to like 256 columns, but the people sending me Excel files don't care.
And it freaks out if you use weird column headers, but the people sending me Excel files don't care.
And it imports empty rows/columns if you don't clean those up first, but the people sending me Excel files don't care.
And yet, if you import these same problematic Excel files into MS Access, it just WORKS.
1
u/tekmailer May 13 '22
Are you familiar with C#? Give the distro a try for your use; if it doesn’t work, help OP write it in.
If not, get OP some coffee. Development goes a long on caffeine, LOL
OP I have something similar working privately in an enterprise. I’ll give this a look-see later.
1
u/government_ May 14 '22
PowerShell can handle this task pretty easily.
1
u/dumpsterninja May 14 '22
Yeah i should take some time to get comfortable with PowerShell; for me it's easier to hammer out a solution in c#
1
u/government_ May 14 '22
It's Import-Excel then Invoke-SqlCmd to insert ForEach row. We're talking no more than 5 lines of code necessary.
1
u/Pennypacker_HE_920 May 17 '22
I have a nice immediate use case for this tool…client provided a file with data for each week on separate tabs. For a one-time need I can just brute force merge the sheets, but would also like to schedule this to run in the future.
That said, I’m a novice with GitHub. Can you offer a quicker download/set up guide for getting the program up and running? I watched the YouTube video but it doesn’t cover the original set up. I think once I get to the point of setting up the json setting, I should be good (bc of the YouTube video tutorial)
Thanks!
1
u/dumpsterninja May 18 '22
Sorry for not seeing this sooner, you can download already compiled releases from: https://github.com/TimBurris/ExcelToSqlServer/releases Then expand assets and grab the zip
I have some tweaks coming tomorrow but v0.2 there should get you going
PM me if you have any questions or need some help
2
1
1
1
1
10
u/Black_Magic100 May 13 '22
Why reinvent the wheel?
https://docs.dbatools.io/Import-DbaCsv