r/SQLServer • • 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.

27 Upvotes

25 comments sorted by

10

u/Black_Magic100 May 13 '22

1

u/dumpsterninja May 13 '22

Does that utility do excel files? It looks like it does CSVs (which are not Excel files, obviously Excel is a popular tool for opening csvs but they're not Excel files)

I was looking to target actual XLSX files which have formulas, spanning, and all kinds of stuff

That being said, the link you sent does look pretty great for CSVs.

3

u/Black_Magic100 May 13 '22

Excellent point! My mind is conditioned to think of CSV whenever I hear Excel even though, as you pointed out, they are fundamentally different. I usually convert xlsv files to several csv files and then upload that way personally although the CSVs I mess with don't have formulas so I'm not sure if converting to CSV is even possible in that case? I wonder if it just flattens the final value?

2

u/dumpsterninja May 13 '22

Converting to csv can be a good option, it will indeed put the computed value into the CSV.

So you're definitely right when possible that's a good path to go.

One of the limitations, though, is multiple worksheets. a lot of my examples I need to bring in all the data from all the worksheets.

I don't know if there is a native way to have Excel create separate csvs for each worksheet but even then you have to run the import process against all the separate csvs. In my particular case, which finally pushed me to create the utility, the client had 85 worksheets and each worksheet was named with its parent record value so I needed to bring in all those worksheets with the worksheet name so I can match it up to data in the database.

regardless, I definitely appreciate the reference to that CSV option because I do get a lot of CSVs as well :-)

1

u/tcote2001 May 14 '22

Alteryx can do all this for you with no code inclusive of dynamic inputs for multiple worksheets. Does your tool consume functions (and translate them to Sql) relative to assigned columns and migrate those to sql server too? That would be dope.

1

u/dumpsterninja May 14 '22

No it does not convert formulas to sql code, just gets the computed value. That would be cool, but the purpose of this is to be an uncomplicated way to get raw data in.

Is Alteryx free? The one that I found, using my AOL web crawler, was a paid tool whose angle is provide a complete tool with data translation and migration whereas I'm focusing on just getting the data in and letting the technical expert use T-SQL to manipulate the data

1

u/tcote2001 May 14 '22 edited May 14 '22

No, Alteryx…it’s a very expensive all in one BI tool. If I was going cheap with Microsoft tools I’d prob use power BI and push to Sql Server but that only works if tables are already present.

1

u/Black_Magic100 May 13 '22

That makes sense! DBATools is an awesome PowerShell module btw. You should check out their other cmdlets.

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

u/TheMoskus May 14 '22

No bagels?! I may or may not be disappointed.

1

u/infernalspacemonkey May 13 '22

Nice! I'll check it out. Thanks for sharing!

1

u/ComicOzzy May 14 '22

I'll check it out. You might be my new best fren.

1

u/[deleted] May 14 '22

PowerShell is your friend

1

u/CompetitiveInvite710 May 14 '22

Why not use SSIS?