Updating a table based on an Excel file without excel functionality? - sql

Okay, so I basically have a huge excel list with two columns, ID and Value. I'd like to update an Employee table in my SQL and set a column in that table equal to the Value from the excel file where the ID of the excel file is equal to the ID of the Employee table.
I've looked at other similar questions and they use OpenRowSet and other SQL excel functionality, but unfortunately it looks like our DBA hasn't installed any of that. What can I do as an alternative to update that table?
As for what I've tried, I created two XML lists and separated each column of the DB into a temporary table so now I have two temporary tables, one for each excel column, but now I'm reading that combining two tables without a common identifier is really bad practice so I'm back at square one.

You can do that easily using SSIS. You can use excel source, Lookup transformation or Merge Join and OLE DB destination.

Related

Joining SQL Database Table with Excel Sheet Data Using Power Query

I'm accessing a table in a SQL database through Excel Power Query and I want to do a join with some data that I have in a excel sheet. I don't have write access to the database so I'm not able to just create a table with the Excel data there.
Is there a good workaround that would allow me to join the database table with the data in the Excel sheet?
If you load the data from the SQL database in a query you can merge it with another query in the power query editor. You just have to navigate to the power query editor and find the merge button.
The editor will ask which are the two queries you want to merge and to indicate which columns contain the matching data.
Several types of join are supported.

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.

Replace part of oracle database with data in excel

I have a table with 103 columns and more than 100,000 records. I was told that Oracle Data base has bad data in few of the columns(four columns) and in few of the records(20,000 records approx) and was told to modify data. Also I was given a query where I should modify data(bad data). With the help of query, I exported all the bad data into excel and modified using macros.
How to replace existing bad data in Oracle data base to data which I have in excel(good data). Is it possible to modify data in some part of the database using SQL query? I mean to say 4 out of 103 columns and 20k out of 100k records has to be modified without affecting already existing good data in Oracle database.
I am using SQL developer and Oracle 11g
My query to retrieve bad data
select e.id_number
, e.gender_code
, e.pref_mail_name
, e.prefix
,e.first_name
,e.last_name
,e.spouse_name
,e.spouse_id_number
,e.pref_jnt_mail_name1
,e.pref_jnt_mail_name2
from advance.entity e
where e.person_or_org = 'P'
and ascii(e.spouse_name) <> 32
or ascii(e.spouse_id_number) <> 32"
Note: Moreover I am not changing any primary key or secondary key data. Bad data is in other columns.
You can start by importing all corrected data (which now resides in your Excel file), to a temporary table. See Load Excel data sheet to Oracle database for more details.
The it should be a simple task to write one or more UPDATE statements. If you are new to Oracle syntax, Tech on the Net has some nice examples.
Also, do not forget to backup the original table to a temporary table before you make any changes there. That way, if you mess up the data repair, you can start over.

Importing Excel data using SSIS using unique ID's

I have one excel file that I want to import into two different tables, tblUni and tblUser.
I have a third table which contains the id's from the other two tables:
tblUni_Students
Id
UniId
StudentId
What I need is when I import the excel data into the first two tables, for each record, the newly created ids to be inserted into the Uni_Students table also.
Using SSIS, I have managed to import the data into two sql destinations but cannot seem to then take the new ids from these destinations to then insert into the lookup table.
Can anyone advise please. Thanks.
It's a bit difficult to answer without knowing the target database or the structure of the data but speaking generally this would be much better done by adding the data into a "load" table. i.e. one who's sole reason is to temporarily hold data while you process it, you would then update the tblStudent, tblUni and tblUni_Student tables from the load area using SQL statements either via Procedure or via an Execute SQL Task component.
You'd it as an oledbcommand component, where the command is to insert values into the table. Then in the same component you'd output the generated identity. Assign the generated identity to a new column in the output, and now you have all your data plus the generated identity in the dataflow.
This will be processed one row at a time, so it will be slow. Personally I'd put it in a staging table and do it as CiarĂ¡n described.

How to populate look up tables in sql?

Hi i am working on look up tables first time and we have some distinct values in look up tables which are coming from excel sheets. So i have two databases say A and B. there are around 22 look up tables and 5 certified tables in database A. and one import table and few work table in database B. i am just wondering how i am going to load Look up tables. do i have to write stored procs for each look up table and use in SSIS package. i just have to get distinct values from the Excel sheet for respective look up tables. i am using SQL Server 2005. Thanks for reading this.
1) Save the excel sheet as csv (use "Save As" from file menu)
2) Set "IGNORE_DUP_KEY" option on the destination table, this will skip duplicate values in CSV files(excel sheet)
3) construct a BULK INSERT command and provide the csv file and the destination table.
Alternative to 2) You may also set MAXERRORS in the BULK INSERT command to a value higher than the number of lines in csv file, this options just ignores any errors(there fore all the duplicate key errors will not cause the INSERT to fail)