SQL - multiple incognito parameters from single cell - sql

I've been searching for this "issue" but I couldn't find anything. I'm not sure about how to explain it so, maybe I searched it in a wrong way.
If not... I have this SQL embedded to an Excel spreadhseet
SELECT
PlanNo
FROM
tablex
WHERE
PlanNo IN ('12312','123',1456')
I would like to set the "WHERE" in order to link it to a cell in my excel spreadsheet but if I do this below in order to have multiple parameters taken from a single cell, it doesn't work:
SELECT
PlanNo
FROM
tablex
WHERE
PlanNo IN = ?
I try to put these below into, for instance, my cell B2 but I can't make it work.
'7090001701','7090001512'
"7090001701","7090001512"
('7090001701','7090001512')
("7090001701","7090001512")
Any suggestion?
Thank you very much in advance,
cheers

Related

How to add constraints with a large amount of objects in SQL query?

I want to get output from a SQL query by adding
WHERE ID IN (
15325335122,
85962128962,
12354789522,
64125335125,
64523578945,
12354784589,
......
........)
This list contains over 9000 rows, I'm wondering if there's an easy way to add them in the where statement since I don't want to copy and paste and add comma one by one. I'm new to SQL, can someone help me? Thanks in advance.
I've figured out the solution by following this instruction
In excel, select the cell next the first cell next to the first item on the right, then enter =A1&","

Excel SQL Connection: Have a query update based on a cell value

So, in short, I need to connect from data to a SQL query. I had not trouble doing this with a fixed query. I however, want that query to update based on values in certain cell. Since the person using it might not be familiar with SQL, Excel, or VBA, I was tasked with making the data update simply with the Excel refresh button. Anyway, super simplifying, I want to run a query like this:
SELECT
column1, column2, column3
FROM
table
WHERE
important_date BETWEEN [A1] and [A2]
AND thing1 IN [list from A3]
AND thing2 = [A4]
I saw this thread here: Excel: Use a cell value as a parameter for a SQL query and it did not seem to answer my question for 2 reason:
One work-around seemed to require that the table itself be pulled into excel. The table in question would contain millions of rows, making his infeasible.
Some suggested a question mark (?) workaround, but entering ? for dates, lists, or strings simply outputted errors.
Given this, is there a possible way for me to do this? If so, how? and finally, if I can, how would I go about dealing with a blank list? For instance, if someone does not list anything in A3, I'd like the query to simply ignore the "AND thing1 in [list from A3] part of the code.
Thank you,

Excel SQL Table Formula's clearing

Apologies if asked elsewhere, having checked couldn't find anything. I've got a SQL driven table in Excel. When my table refreshes, resulting in no data, it completely clears out a series of none-SQL driven columns on the far right of the table. Is there any way at all I can force Excel to store the formula on the cell, regardless of whether the row has cleared?
To ellaborate on my comment:
Below shows a simple query returning 10 dates from a database. The right column is a simple formula in excel adding 10 to the date:
If I update the query to return the top 0, you find the formula disappears because there are no values to assign the formula to:
But, I then update the query to bring back the original 10 dates again, and hey-presto, the formula re-appears!:
So I wouldn't think that you need to worry that it has gone. I would expect that they would come back once you return some values from your query.
FYI - More help on calculated columns can be found here from Microsoft support.
Thanks! I think I had 'preserve column sort/filter/layout' unticked - which was causing the formula to be lost when the data refreshed! Schoolboy error, thanks again

SQL From Excel VBA: Create a temporary table in VBA (for reuse) from a SQL query

I have been going nuts looking for a straightforward way to do this, but most answers I have come across go off on a tangent instead of directly addressing the question.
Here is a simplified SQL snippet I am trying to run through VBA
SELECT * INTO ##Customers FROM Addresses
SELECT * FROM ##Customers a LEFT JOIN PostageRate b ON a.ZipCode=b.ZipCode
And then I need to put all this data into an Excel sheet.
So far I am able to execute:
SELECT * FROM Addresses
This is the functional equivalent of the first query without the temporary table. I land up with a RecordSet which I then put into a sheet using CopyFromRecordSet, but I don't know how to turn this RecordSet into a table so I can query it for the second query where I do the LEFT JOIN and then put the resulting RecordSet on the sheet.
Naturally the queries I am trying to run are more complex than this one, but this illustrates what I am trying to achieve.
Apologies if I have missed a post that does answer this, but I have yet to come across it.
Thanks!
EDIT: I have looked into putting the data from the first query onto a sheet and treating the sheet as a table for the second query. The problem is as follows:
The sheet is local and the second table is on a database. According to this question, the database would need to have access to the Excel sheet. It does not. Any more insights about how to achieve temporary tables through VBA would be greatly appreciated. Thanks all!
SELECT * FROM
(SELECT * from [Addresses]) AS Customer
LEFT JOIN PostageRate
ON (customer.zipcode = PostageRate.zipcode)

extract data in exel sheet using macro

you most probably going to think "what an idiot" but remember i never done any type of coding before so this is all new to me,
My problem are that i'm working on a HUGE excel sheet with loads of data that is not needed. i need to sort the data into a few columns, i only need column "A,K,AN,AQ" but in column "AS" i only need certain values (yes,no,blank) i only want the yes and blank values. like i said never done any coding before but i know that you can use an macro to do it so please help, how do i go about this?
before trying to get into macros, try to use functions with if else statements. They are quite easy to handle. Like: If (yes) then put it into X. Later, you could select all needed. Also, check the, how the dollar sign is used
use this links to see, if it is something for you.
One quick and dirty way of getting this job done would be to:
Delete the columns you don't need.
Select all cells in the range you're interested in, click the Insert menu, and choose "Table". If your columns have titles, select the box for "My Table has Headers."
-This turns your data into an array so that Excel recognizes that each row is an entry (instead of thinking that the cells are unrelated).
Now you can use the filter icon in the column headers to select and display only the rows containing the values in column X that you're interested in.
Note that there are some limitations to what the table feature is good for, so, as always, whether this is a good solution for you depends on what you want to do with the data.