Populating SQL database table by retrieving data from Excel spreadsheet - sql

I'm new to SQL (but have experience in other programming languages) and I'm taking on a side project at work that involves creating a database of our team's financials. Ultimately what I want to do is have this database retrieve data from a specific table in a worksheet and then populate a database table. I'm sure this is possible but how would I go about doing this? I'm currently familiarizing myself with PostgreSQL as I found it to be the most beginner friendly.

I am using Dbeaver where i can export the data of any table in to CSV , once i have data in CSV , i can create .sql file back using online http://codebeautify.org/csv-to-sql-converter which then can be executed on any other same db.

This will help get you a cell range exported to CSV:
Export sheet from Excel to CSV
Then use this to get the CSV into PostgreSQL:
How to import CSV file data into a PostgreSQL table?

Related

How to compare one large dataset in DB and one large dataset on SpreadSheet?

I am trying to compare two large dataset which have two columns- Company name column and Contact person name column. One dataset is already in database and one set is on Excel SpreadSheet.
I try to compare two dataset and try to update database.
For now I download data from database and comparing two dataset using Pivot Table function in Excel. This kinds of work. But I hope is there any other better way. Any suggestion will be appreciated!! Thank you.
FYI my database uses MSSQL 2008.
Upload your excel file as .CSV to database, next either create a table for it or just use a temporary table to place the data from the CSV file. Proceed to compare the data from that temporary table to the table on your DB with a Join.
Upload the data from the excel work sheet as a csv file to the database, and save the contents in a different table. Then compare both tables with a join.

How to Overwrite Database Table Data Using SQL Server Data Tools

I'm currently working on a small project using sql data tools. I'm getting data from excel sheet and write it back to my database table. from the database table I'm generating a report. Time to time I'm updating my excel sheet. but it won't update in my database table. how do I clear the table and rewrite excel sheet data to database table when run the project every time?
post build script would be how and when I would clear or synchronize the data. Then you have to write the truncate or delete and the insert and/or update sections to move data from your excel document to the sql table. I would suspect that the SQL table is a better place to maintain the data though!!! If you maintain in SQL you can always have a query to see what it is in Excel at any given time and you don't have to worry about synching back to SQL.

Excel database values to SQL Server and different tables

I got an Excel file with data which I want to import into a database in Microsoft SQL Server 2008 Express edition.
I do this with right click on a database -> task -> import data.
After this, my data from Excel is loaded in the database in one table.
But I want to seperate the columns from the Excel file into different tables.
So instead of loading all Excel data into one database and table, I want to load the Excel data into one database, but in different tables.
For example: Save column 1,2,3 from Excel in table A, and save column 4,5,6 from Excel in table B.
Anyone that knows how to do this?
I followed the suggestion of #bendataclear:
"Personally I would just import into a temporary table then write INSERT INTO X SELECT queries to move in the correct columns."

How can I join Excel column and SQL View?

I have an Excel spreadsheet, with one worksheet, with one column, containing key values I want to use to lookup data in a SQL Server view.
I can import the view data just fine using ADO or ODBC, but cannot figure out how to have the "Microsoft Query" tool add both the Excel Worksheet and the SQL View in a single query, so that I can join the data. I had also hoped VLOOKUP might lookup external data, but did not find anything,
I have looked for hours and am stumped. Certainly this can be done somehow where I can use a key in an Excel file to fetch a single related SQL table row back into Excel? I'm a hard core C# developer but seem to regularly struggle with Excel...
I would import the excel data into a staging table in your SQL Server database.
Of course you can use ADO to get the excel data into SQL Server.
Then you can join the view with your staging table.
hope this helps.

BCP utility to create a format file, to import Excel data to SQL Server 2008 for BULK insertion

Am trying to import Excel 2003 data into SQL table for SQL Server 2008.
Tried to add a linked server but have met with little success.
Now am trying to check if there's a way to use the BCP utility to do a BULK insert or BULK operation with OPENROWSET, using a format file to get the Excel mapping.
First of all, how can I create a format file for a table, that has differently named columns than the Excel spreadsheet colums?
Next, how to use this format file to import data from say a file at: C:\Folder1\Excel1.xsl
into table Table1 ?
Thank you.
There's some examples here that demonstrate what the data file should look like (csv) and what the format file should look like. Unless you need to do this lots I'd just hand-craft the format file, save the excel data to csv, then try using bcp or OPENROWSET.
The format file specifies the column names for the destination. The data file doesn't have column headings so you don't need to worry about the excel (source) cols being different.
If you need to do more mapping etc, then create an SSIS package. You can use the data import wizard to get you started, then save as SSIS package, then edit to your heart's content.
If it's a one-off I'd use the SQL data import size, from right-click on database in mgmt studio. If you just have a few rows to import from excel I typically open a query to Edit Top 200 rows, edit the query to match the columns I have in excel, then copy and paste the rows from excel into SQL mgmt studio. Doesn't handle errors very well, but quick.