Creating a custom "WHERE" filter in Excel SQL connection - sql

I have easily created a custom SQL Query to populate an Excel from an SQL database.
This was quite straightforward and easy (Data/from External sources/Microsoft SQL - and then edited the command text section of the connection properties)
But now, I would like to use a WHERE clause with a parameter from a cell.
From what I read on every tutorials and similar SO questions, I should simply have to use a question mark and Excel will understand it and allow me to define a cell.
Sources:
How to add parameters to an external data query in Excel which can't be displayed graphically?
That's what I did:
Unfortunately I got this dialog telling me that some info are missing:

You should use Microsoft Query first , and then change the Command Text later.
Refer from this: Excel: Send multiple values in "Command text"

Related

How to insert Dynamic SQL in list and labels?

How to write a Dynamic SQL query with bind/substitute variables in List and Labels report server?
When creating the Datasource I have the option to enter the query manually, but as soon I enter the bind an error message is displayed.
I want to be able to enter a dynamic query in the datasource and set the value of that bind/substitution variable.
This is something that's actively being worked on. This blog post covers the basics for parametrized data sources within List & Label itself. Thorough support within the Report Server, including support for stored procedure parameters, is on the roadmap and will be released this fall.

Excel - Off Page Reference to Microsoft Query

I am utilizing Microsoft Query in Excel to tap into an ERP table structure like Crystal would do.
In writing the SQL, is there a way to have a filter pulled from the active Excel worksheet that is embedded in the SQL instead of prompting and editing the query?
My main problem is a Like [Prompt]% in the Excel GUI for the users to change like order numbers.
Is it possible to do an off page reference from MS Query to Excel?
If by "Microsoft Query", you're talking about the window that looks like it was coded for Windows 95, stop using it. This is provided for retro-compatibility.
Anyway, if you've displayed the criteria bar in MS query, you can type a name between brackets e.g. [Something] and MS query will prompt you to fill a value.
Not what you want yet but getting close. When you return to Excel and refresh the query, the prompt will now offer you the possibility to use a cell instead of a value you need to type every type.
In the more modern connection utility accessible via menu data > Connections (+ available even if you created your table via MS Query btw), you can achieve that by using question marks in the WHERE clause.
For instance, instead of SomeField = 'SomeValue', write SomeField = ?
Then, click on the Parameters button and you'll see all the parameters you've set, each of them can be attached to a cell's value.

How to query access table with a subdatasheet that requires parameters

I have been tasked with creating a method to copy the contents of an entire database to a central database. There are a number of source databases, all in Access. I've managed to copy the majority of the tables properly, 1:1. I'm using VBScript and ADO to copy the data. It actually works surprisingly well, considering that it's Access.
However
I have 3 tables that include subdatasheets (to those that don't know, a subdatasheet is a visual representation of a 1 to many relationship. You can see related records in another table inside the main table). When My script runs, I get an error. "No value given for one or more required parameters." When I open Access and try to run the same query that I've written in SQL, It pops up message boxes asking for parameters.
If I use the query wizard inside Access to build the select query, no parameters are required and I get no subdatasheet in the result set.
My question is this: how do I write a vanilla SQL query in my VBScript that does not require parameters and just gives me the data that I want?
I've tried copying the SQL from Access and running it through my VBScript and that doesn't seem to do the trick.
Any help is greatly appreciated!
As it turns out, you need to make sure that you've spelled all of the field names properly in your source query. If you've included additional fields that aren't actually in the source or destination table they'll need to be removed too.

How do I edit the BigQuery Connector for Excel .iqy file to have the SQL statement already in it instead of relying on input from an Excel cell?

I'm having an issue similar to bigquery excel connector - query larger than 256 char
However, I AM referencing a cell range and get the result:
"WARNING Request failed: Error. Unable to execute query. 400 { code : 400, errors : [ { domain : global, location : query, locationType : other, message : 1.593 - 1.593: No query found., reason : invalidQuery } ], message : 1.593 - 1.593: No query found. }"
Perhaps I'm "splitting" the query incorrectly? I assumed each cell only needed to be less than 256 characters, and it would just concatenate subsequent cells in the range specified to the end of the string in the preceding cells.
Every help document I've found show simple SQL statements, and I can run simple ones, but the query I really need to work has a select statement in the where clause for a field. I've tried joining the table referenced in the where clause to see if that makes the statement simpler, more easily recognizable as a query, but no luck.
I've tried opening the .iqy file in NotePad that (BigQuery originally had me download) to see if I could just input the query there, but I cannot find any documentation for syntax on these types of files so when I load it into Excel it still shows a prompt for the query to be inputted.
The final result doesn't need to have the query read from a cell reference, in fact, if it could all just be in the .iqy file, that would be most preferable: less chance of users mucking up the data.
Make sure to URL encode the parameters (query, project and key) in .iqy file. Use an online tool like https://meyerweb.com/eric/tools/dencoder
if you had the .iqy loaded already in Excel before making above changes, you must delete the query definition. Go in Properties and uncheck Save query definition, then connect to the .iqy again
Not sure what the max size for q(query) is for https://bigquery-connector.appspot.com but I recommend using a BigQuery VIEW instead.
it hides the SQL plumbing and hence reduces the size of the SQL passed to the API. URL encoding the query can then be as easy as replacing spaces with +
you can tune/change the view definition in BigQuery without having to rollout a new .iqy to your users
implement some sort of row-level security using CURRENT_USER()...
But that's another topic !
Finally, coming back to the .iqy, you can combine and embed parameters in the query like so:
q=select+*+from+mydataset.myview+where+FiscalYear=["Year", "Enter a year:"]&p=myproject&k=myURLencodedKey

Excel SQL data import parameter issue

I tried to find the answer myself but not knowing how to word the question caused problems :).
I have an excel workbook that I use to pull data from SQL Server 2005 using a stored procedure that accepts a parameter. I am using Microsoft Query in Excel. I am trying to get Excel to grab the parameter from a cell so that the users will not have to edit the connection. If I were to do this as SQL, I would replace the value with a ? and point it to a cell without issue. Since this is a SP, I get a strange response.
This works:
exec [GTI_mainframe].[proc_mf_forecast_authorizations] .07
This:
exec [GTI_mainframe].[proc_mf_forecast_authorizations] ?
Gives me the following message box:
[Microsoft][ODBC SQL Server Driver]Invalid parameter number
I control the SP and the excel workbook so can impliment what I need to. I had one person suggest a vba approach to reference the cell value directly. I could do that but my choice would be to not have to do it in macros. I would love to just be able to use the "refresh all" from the data tab in the ribbon bar. Any thoughts?
I recommend you XLReport; it allows you to connect to almost any database, create queries with parameters.
You can download the trial here.