VBA: Connect to MySQL and Compare - mysql

I am coding in VBA to write a macro that essentially does 2 things:
Connects to a MySQL database MYDATABASE, which has one table
Loop and compare all of the values in a column of an Excel Spreadsheet and compare to a column MyColumn of a MySQL table MYTable
To be specific, my table has three values. An ID, a name, and a number. In my excel sheet, I would have much more information, including ID, address, city, and number. However, there would be no name.
I want to loop through the values of the number column in my spreadsheet, and compare the numbers to numbers in the MYTable table. Then, it would pull all associated names to those numbers and place those numbers in an adjacent column in my excel sheet. For the purpose of this macro... the column I want to loop through is column C.
I found this question: How can VBA connect to MySQL database in Excel?
which explains how to connect to VBA.
So how would I go about this?

I would load the excel data into a second MySQL table and then write a simple program to do the comparison between the 2 MySQL tables.

Related

condtional split SSIS where both data sources have Nulls

I am using ssis 2010
I have a conditional split
Source A Column ID - An Excel sheet
Source B column ID (1)- A table of Customers
I only want to add data to a table from the excel source, if the ID does not exist in the table
ID contains a combination of letters and numbers
normally this would work
!ISNULL(ID) && ISNULL([ID (1)])
but there can be instances now, where both the Excel Source and The Data Table can have nulls for the ID column
How do I amend the above to cater for nulls please. I have tried other code, but I get the Conditional split error about Boolean data
The typical model looks like this:
source Excel ==> Lookup (check if ID exists in table redirect no match) ==> Load NoMatch
I am unsure what you are trying to do with nulls in ID columns???

How to Guess schema in Mysqlinput on the fly in Talend

I've build a job that copy data from a mysql db table to b mysql table.
The table columns are the same except sometimes a new column can be added in table a db.
i want to retrieve all the columns from a to b but only those that exists in table b. i was able to put in the query specific select colume statment that exists in table b like:
select coulmn1,column2,columns3... from table a
the issue is if i add a new column in b that matches a the talend job schema in Mysqlinput should be changed as well cause i work with build in type.
Is there a way to force the schema columns during the job running?
If you are using a subscription version of Talend, you can use the dynamic column type. You can define a single column for your input of type "Dynamic" and map it to a column of the same type in your output component. This will dynamically get columns from table a and map them to the same columns in table b. Here's an example.
If you are using Talend Open Studio, things get a little trickier as Talend expects a list of columns for the input and output components that need to be defined at design time.
Here's a solution I put together to work around this limitation.
The idea is to list all table a's columns that are present in table b. Then convert it to a comma separated list of columns, in my example id,Theme,name and store it in a global variable COLUMN_LIST. A second output of the tMap builds the same list of columns, but this time putting single quotes between columns (so as they can be used as parameters to the CONCAT function later), then add single quotes to the beginning and end, like so: "'", id,"','",Theme,"','",name,"'" and store it in a global variable CONCAT_LIST.
On the next subjob, I query table a using the CONCAT function, giving it the list of columns to be concatenated CONCAT_LIST, thus retrieving each record in a single column like so 'value1', 'value2',..etc
Then at last I execute an INSERT query against table b, by specifying the list of columns given by the global variable COLUMN_LIST, and the values to be inserted as a single string resulting from the CONCAT function (row6.values).
This solution is generic, if you replace your table names by context variables, you can use it to copy data from any MySQL table to another table.

Mapping database columns to excel spreadsheet

I have a table that contains ~100 columns and I have to generate an excel sheet out of it. The output excel columns are like "Total Actual FY SY-2/SY-1" and I can't have that as my database column for sure.
My question is how can I map database columns to excel columns? How can I know for example if "TotalActualFYSY2SY1" in database should be "Total Actual FY SY-2/SY-1" in excel?
Should I have another table to map the database column names to the excel column names?
I'm not asking for solution in any specific programming language.
(The system is going to be developed using SoftwareAG WebMethods)
There are various solution to this, you can do the same via using alias name in SQL Server for example
SELECT TotalActualFYSY2SY1 AS 'Total Actual FY SY-2/SY-1'
FROM YourTable
This will output your column in desired name. Alias name in SQL is the temporary name to assign to the column or table.
Another way is to fetch rows from SQL Server and change the column name from any programming language itself.

SSIS to import data from excel into multiple tables

I have an Excel sheet (input) where each row needs to be saved in one of three SQL server tables based on the Record type (column 1) of the row.
Example:
If the Record type is EMP, the whole row should go to the Employee table.
If the Record type is CUS, the whole row should go to the Customer table
I am trying to use a multicast and not sure how to split the data from multicast to the destination table. Do I need any other control in between?
Any idea would be appreciated.
A Conditional Split Component sounds like just want you need. A Conditional Split uses expressions you define to route each input row to one output. In your case, your Conditional Split would define three outputs, each of which would be attached to a SQL destination.
In comparison, the Multicast Component you're currently using sends each input row to all outputs. This component would be useful if you were trying to save a copy of each row to all three SQL destinations.

How to create a flatfile from a series of tables in Access?

I have a series of tables in an Access 2007 database. I am trying to find a way of outputting a flat-file to an excel spreadsheet that combines all of the tables so that each row of the flatfile represents a unique combination of the table rows from each table.
For example, these tables:
Would combine to make this output table:
The challenges I'm facing are:
The 'input' tables can vary in number of rows and columns, as well as quantity
The total number of rows in the final output table can get quite large (200,000+ rows)
I know Excel and VBA (in Excel) well but almost nothing about Access
Is there a way to do this in Access? Is there some native functionality in Access that I'm completely overlooking? Any pointers (even if it's "you need to read into X and Y") would be greatly appreciated!
Thanks,
Adam
As noted above:
Create a new query. Select your 3 tables as the data sources. If desired, set up joins between tables by dragging a line between a field in one table to a field in another. Without joins you will get a Cartesian Product ... every from 1st table paired with every row of 2nd table, and then each of those combination paired with every row of 3rd table. Select the fields you want included in the result set. When the query returns what you need, save it and give it a name. Then you can export that named query to Excel.
If the table is large, you could hit Excel's row / column limit though.