Search SQL table using excel to return only matching values - sql

I have a large table in my SQL database with a few million rows so I can't just load it into excel. I'd like to setup a data connection in Excel to the database which I can do now, but I want to be able to open the excel sheet, type my search parameter in a cell and then have the matching rows returned from the database table into the excel sheet.
Does anyone know if that's possible? I can't find a way to do it without manually adjusting the search term in the connection properties because I don't know how to pass along what I typed in the cell to be the search term.

Ok figured it out, microsoft has a great guide for it here:
https://support.microsoft.com/en-us/office/create-a-parameter-query-in-microsoft-query-c67d9af7-c8a0-4bf7-937c-087cb25f7ad3

Related

Use an Excel Cell as a Input Data for filtration to a SQL Server View

I have a basic view in SQL Server which includes these columns,
"Lot Number" , "Time" , "Code" , "Name" , "Barcode"
Now I need a Excel file which will have EXACTLY the same columns and the same information.
What I want to do is, in the Excel file when I write a number to "lot number" section, the other columns will fill itself automatically based on the SQL Server view. Basically I'll be using "lot number" cell as a filtering.
The problem is that, this is a ERP system database. I don't want to extract all the information to Excel file, there are millions of rows. Excel should be blank, I will write the lot number first, then refresh the Excel file and the other columns should be filled in automatically. I will refresh the Excel every 1 min automatically and only 1 row is enough.
So I need a procedure in SQL Server (or in Excel) to receive data from the Excel cell, then use that data for filtration in a view and return the data to the same Excel.
Now I'll show you my set up, waiting for your ideas.
This Screen shot is the SQL Server view in "192.168.2.100" server. My SQL knowledge is pretty basic, I create views by schematics not by codes.
And this is the Excel file that I connected. As you can see I can extract all the data. (I deleted code-name-barcode cells. they are not empty, because these are official information).
Obviously this is not I want. When I put the lot number I want other data to came automatically. At least when I refresh the Excel file. Excel is in "192.168.2.116\\barkod\\Tyvek_Mdr.xls" . It is in a shared network.
So I have been researching but still I couldn't find the best solution. If someone can help me I'd really appreciate it.

Is there any way use the values in a cell to query a SQL table and see if the value exists in the table?

I have an Excel spreadsheet containing all of my company's Vendor Codes. When a new code is added to this spreadsheet, we then add it to a configuration table within our database which allows us to accept that vendor. Right now I'm going through my Excel Spreadsheet and reviewing each section of code to find out if it exists in the SQL Table.
Is there any way use the values in a cell to query my VendorConfig table and see if it exists?
Spreadsheet Columns: VendorID, VendorCode, Config
You could use the "get external data" command to bring a value into a cell to check against. Alternatively, here is a link to a web post that has a cool answer to this problem (NOTE: I haven't actually tried this code but, from a quick glance, it looks right): Add formula to excel to validate data

In SQL how do I update a table with a similar table?

In my current Database I have a table whose data is manually entered or comes in an excel sheet every week. Before we had the "manual entry option", the table would be dropped and replaced by the excel version.
Now because there is data that only exists in the original table this can not be done.
I'm trying to find a way to update the original table with changes and additions from the (excel) table while preserving all rows not in the new sheet.
I've been attempting to simply use an insert query and an update query /but/ I can't find a way to detect changes in a record.
Any suggestions? I can provide the current sql if you'd find that helpful.
Based on what I have read so far, I think I can offer some suggestions:
It appears you have control of the MS Access. I would suggest adding a field to your data table called "source". Modify your form in the access database to store something like "m" for manual entry in the source field. When you import the excel, store an "e" for excel in the field.
You would need to do a one time scrub of the data to mark existing records as manual entries or excel entries. There are a couple of ways you can do it through automation/queries that I can explain in detail if you want.
Once past these steps, your excel process is fairly simple. You can delete all records with source = "e" and then do a full excel import. Manual records would remain unchanged.
This concept will allow you to add new sources and codes and allow you to handle each differently if needed. You just need to spend some time cleaning up your old data. I think you will find it worth it in the end.
Good Luck.

Access - Create Select Statement via Excel Template

to export data from an Access 2010 Database I would like to use an Excel template as seen below.
In the first row I can define columns that are in the database. In the second line I can define exactly 1 filter which will be used in the "where" statement.
When pressing a button in Access, a query that is based on the defined columns and filters should be executed and the result will be exported to the Excel.
I am honest, I am not that skilled in VBA. What would be the best point to start from.
Your question is way too broad and as such it should not even be here, but let me give you some points to look at.
First you'll need to get your data from the Excel file. If you are not skilled with VBA, then the easiest way would be opening it through VBA using an Excel.Application object and Workbooks.Open method, and get your values from your Range.
Create an SQL Select statement from your values.
Do not use just a SELECT query, make it a SELECT INTO query (a "make table query" as Access likes to call it). That way your results will be inserted into a (new) table, making it easier to output.
Export your new table to Excel. There are several ways to do this, search for DoCmd.OutputTo or DoCmd.TransferSpreadsheet.

collecting SQL statements using Excel

in my everyday work, I am receiving data in Excel spreadsheets, which I need to insert into relational database.
To accomplish this, I prepare formulas which generate "insert" statement (I am using both insert and select statement for example to choose ID of all elements with specific label).
Because those spreadsheets are complex, they contain SQL commands in more than one column.
This is the point where problems begin - I cannot simply select all cells, copy them and paste into SQL Server (it will concatenate information from cells in the same row).
In most cases I'm preparing additional sheet where I'm collecting all statements in one column
(using simply formula which rewrite text from other cells). Unfortunately preparing such sheet is time consuming and might causing an error (for example if I forgot about column or I add rows).
Is there any more convenient way to do it?
I thought about writing a macro which collect all values from selected range.
Is it good idea or can I use something better?
You can do all that using VBA.
You know what are the rules so you have the business logic in your head. Now, just type the code to do it :)
If you want you can do the insert in the Excel using something like this.