Hi I have an Excel sheet with quite a number of data inside, and now I want to perform queries directly in the sheet using VBA. One query is to find the recurring users, so when I implemented it in MySQL I used the DATEDIFF function, so is it possible to do this in Excel? I've tried to embed the SQL statement into VBA, but it failed. Thank you!
My original SQL statement is like this:
select max(logtimestamp), min(logtimestamp), count(logtimestamp), username
from report
group by username
having datediff(max(logtimestamp),min(logtimestamp))>=14
order by count(logtimestamp) DESC;
And it works in MySQL.
EDIT:
I'm currently using ADODB in VBA to embed the SQL queries. Some simple queries have already been implemented, so I suppose my configuration is correct; the problem now is I don't know how to get this SQL query into VBA. It's now giving an error, and it might be related to the DATEDIF (different from DATEDIFF in SQL) function in Excel.
Related
I am using the following formula in Excel to conditionally rank the ballNumber column:
=COUNTIFS(BallByBallTable[matchId],A2,BallByBallTable[batsman],E2,BallByBallTable[ballNumber],"<"&C2)+1
It works ok but the table (which is imported from Access) is now quite large and causes Excel to run very slowly.
Is it possible to convert this formula so I can use it in an Access query?
Thanks
I'm using Data Studio to generate a financial report dashboard and I'm connecting it to CloudSQL MySQL, but my problem here is that it only requires me one table to use as a data source, and one table wouldn't help me at all to generate a financial report at all.
Here's the image of the process of selecting a Data Source:
I tried selecting Custom Query, which according to this: https://support.google.com/datastudio/answer/7088031?hl=en
Select the CUSTOM QUERY option to provide a SQL query instead of connecting to a single table. Google Data Studio uses this custom SQL as an inner select statement for each generated query to the database.
But I don't know what query should I write to have all my database tables as data sources in Google Data Studio.
Regarding Custom Queries: Had a look online, and didn't seem to find a sample CUSTOM QUERY specific to Google Data Studio and Google Cloud SQL for MySQL, however, on StackOverflow, there are a couple of posts on BigQuery Custom Queries that involve joins, that may be useful:
Data Studio query error when using Big Query view that joins tables
BigQuery Data Studio Custom Query
An alternative is to create individual Data Sources each linked to a single table and then link multiple Data Sources through the use of Data Blending, where a common Join Key links all the respective Tables.
In addition, if you could elaborate on your exact scenario, it would perhaps help users familiar with SQL to provide a more precise solution:
How are the tables structured?
How are the tables linked?
What code have you currently tried?
I also had quite a few issues with the Custom Query using the Cloud MySQL Connector by Google for Data Studio.
The resolution for me was to not run SELECT * but rather SELECT each column by name. Not sure why it doesn't like SELECT * but hopefully this helps someone else.
Example of a successful query.
Example of successful query with join.
I'm working on several reports for SSRS written in MySQL via ODBC Adapter. For some reason, Stored Procedures only return a single row of data instead of an expected set of data.
Below is the same stored procedure when ran on an SQL Editor:
And below is the stored procedure's execution result when SSRS tries to run it (both on Query Designer and Report Viewer):
I have also set parameters properly as far as i can tell:
so i wasn't able to find an exact answer as to why this happens on SSRS with MySQL via ODBC. What i was able to find was a workaround:
by executing the command as an Expression rather than as a raw query via the Query Editor:
Now the only caveat for this is that the DataSet Fields wouldn't be automatically generated, and that you have to plot them all manually. A good workaround for this is to first run a blank/null query with only the column names (i.e.: SELECT NULL 'column_name_1', NULL 'column_name_2') then later change the query source to Expression. The good thing about using expression is that you only need minor knowledge about how it works and it reduces the confusion with ODBC '?' Parameters.
Cheers!
I have a passthrough query to pull my "Active Members" from an Oracle database via an ODBC passthrough query. It works great, I can link to members retrieved by the query just like I would an Access table.
My question is, will this passthrough query automatically refresh itself each time I reference it? Or should I specify the update using VBA code? Essentially, each time a user searches for a member, I need my pass through query re-run.
No, there's no auto-refresh of pass-through queries, they're just queries stored in another db's syntax.
What I usually do is create a macro deleting rows from the existing table and running the pass-through query. If the macro introduces too much overhead, however, you could also code the steps in a function with VBA.
good day, i would like to ask if it is possible to update a specific cell in ms access using visual basic. If it is possible, may i ask what would be the syntax to be used? Thanks!
Yes, it is possible.
The syntax would simply be an Update Query.
When you say "..using visual basic". I am interpreting that as using Visual Basic for Applications. Am I correct?
You can either create the query using QBE, and pass in the parameters in the Criteria field within the query.
You could then run the query via code:
DoCmd.OpenQuery "YourQueryName"
MS Reference
If that's not your preferred way, you need to look into constructing SQL strings into VBA.
Check out this StackOverflow question. String concatenation in VBA is different than just writing SQL in Access.
Hope this helps.