Picking column names from an excel sheet in sql server while writing a macro - vba

I am writing a macro for automating some task where i need to pick column names from an excel sheet , use that columns in select statement in sql and then fetch the values for those columns from database table. is there any way through which i can acheive this.
e.g.
in my DB there is a table employee having column names as - empname,empadd,empcontact ,empsal,dep,branch,location and 50 more columns.
my excel sheet is having 3 column names empname,empadd,laction.
now i want my code to pick only those 3 columns which are in excel and fetch the values from employee database.
i.e. select empname,empadd, location from employee;
i tried multiple things but no luck.
it would be great if anyone can suggest some way. thanks

Related

Replicating a VLOOKUP (with column insertion) in MS SQL?

I am trying to replicate a VLOOKUP I have done in Excel in SSMS. I have two tables - table 1 is an application master listing, table 2 is an application listing. I want to simply verify that every column in table 1 has an identical match in table two. I also want to have my results populate with an inserted column, column B with the results.
I have already done a very straight forward VLOOKUP in Excel with a 1:1 match. I now have Col A with the application master listing names, and then the new lookup column B with the 1:1 match.
Does anyone know how to go about this in SQL?

How do I update an SQL table from an excel spreadsheet?

I have an excel spreadsheet with 2 columns and 1000 rows. I need to update a table an SQL with the data. I basically need it updates the column B values for the adjacent values from column A. How would I go about doing this?
You can use the SQL Server Import and Export Wizard. You can feed it comma delineated files and if the first row has the column names. It will do just about everything for you.

Import several excel sheets into one table in Oracle SQL Developer

So I have eight Excel sheets, all with two columns a 13000 rows each. I want to create a table in my database with all this data. Also, I want the rows in the different sheets to match each other, meaning that row 1 in each of the columns in all the sheets, should form one row in the database. Is there any convenient way of doing so?

Replacing a value in an Excel column, based on its value in another sheet

I have a exported Excel sheet from SQL with records for insurance policies held by vendors that visit our office. There are two separate tables that identify the Insurer and the Vendor by a code. The table with the records of all the policies just has the codes for both of them.
Is there a formula that can look at another sheet for a value, and pull in another column from that sheet? Basically there is a key code for each vendor, and I need to replace that code with their actual name from another excel sheet.
Or if there is a simpler way to do this in SQL I could try that too.
In SQL you can JOIN the tables together:
SELECT i.col1,i.col2,v.col1
FROM Insurer i
JOIN Vendor v
ON i.key_code = v.key_code
Adjusting which columns you return as needed, without sample data it's unclear if there needs to be additional criteria in the JOIN.
In Excel you can use VLOOUKUP(), but I prefer INDEX() and MATCH(), below would try to match the value in B1 to a value on Sheet2 in B1:B20, and return the value from the corresponding row from Sheet2 A1:A20:
=INDEX(Sheet2!$A$1:$A$20,MATCH(B1,Sheet2!$B$1:$B$20,0))
There are numerous illustrated examples of either excel method that will be easy to follow.

Compare column names in excel sheet with column names in a table in SQL

I have an excel sheet a large number of columns (~500) and a DB table with similar number of columns. I can run SQL queries on the database. What I want to achieve is to find the columns that are in my DB table but not in the spreadsheet. Checking it manually seems really inefficient.
Have you thought of using ODBC functionality within excel? You should be able to open up the table in excel then use count formulas to ensure that the numbers match.
You may try next semi-manual approach:
select top 1 * from [your table]
In SSMS right click to query results and select "Copy with headers"
Paste special->Transpose into Excel (pivot rows to columns)
Select headers in the existing excel, copy them, paste special-> transpose beside previous
Sort and compare columns