How to transform excel index match to Access - joining 4 tables - sql

I am new to Access and I would like to ask you for help. I have data in Excel (about 50 thousand rows). On first sheet, there are my codes (case sensitive) and on other sheets(2 3 4) I have data that I "vlookup" to first sheet. The unique code is on each sheet but on sheet1 there is more codes - not all codes from sheet1 have additional info from other sheets.
Excel isn't case sensitive so I do it with combination of index and match. But 50 thousand rows is too much for Excel and I need to put it into MS Access.
On sheet1 there is unique code that is randomly generated by another program and it is combination of numbers and small and big letters. I need to display all of them and display also additional information from other sheets.
So I want to display something like this for 50 thousand rows.
Code(from sheet1) | FirstName(from sheet2) | LastName(from sheet3)| Adress(from sheet4)
5kj7tfR |Jane | White | London 3
Here are my data:
The problem is that if for example the code on sheet 4 is missing (I don't have address) then Access shows me just code from sheet1 and additional info like first name is missing even if it exists on sheet2.
I tried this but when something is blank in Excel Access doesn´t show me any data from other sheets. Let's say on sheet1 are case sensitive codes, on sheet2 first names, on sheet 3 last name and on sheet4 address. I need Access to show me all codes and info from all other sheets.
select sheet1.code, Tab.FirstName, Tab.LastName, Tab.Adress
from Sheet1
left join
(
select sheet1.code, sheet2.FirstName, sheet3.LastName, sheet4.Adress
from ((sheet1
left join sheet2 on (sheet2.code=sheet1.code) and (StrComp(sheet1.code,sheet2.code,0)=0))
left join sheet3 on (sheet3.code=sheet1.code) and (StrComp(sheet1.code,sheet3.code,0)=0))
left join sheet4 on (sheet4.code=sheet1.code) and (StrComp(sheet1.code,sheet4.code,0)=0)
) as Tab
on Sheet1.ID = Tab.ID --...these IDs made Access while importing Excel to Access.
How can I show all codes with all data even if some cell is empty?
Thank you!

My research indicates cannot force case sensitivity on linking fields in Access. StrComp() is used to apply filter criteria and force case-INsensitive matches between two tables to be rejected. I can get a UNION to show all case-sensitive matches but cannot group on code values because grouping is not case sensitive. Only option I can see involves VBA converting text to HEX and using that value to join, sort, group.
Place this function in a general module (found at Case-Sensitive Sort).
Function StrToHex(S As Variant) As Variant
'
' Converts a string to a series of hexadecimal digits.
' For example, StrToHex(Chr(9) & "A~") returns 09417E.
'
Dim Temp As String, I As Integer
If VarType(S) <> 8 Then
StrToHex = S
Else
Temp = ""
For I = 1 To Len(S)
Temp = Temp & Format(Hex(Asc(Mid(S, I, 1))), "00")
Next I
StrToHex = Temp
End If
End Function
Calling that function in query returns desired output. Copy/paste or type into SQLView of query builder. I initially built query with joins on code fields then switched to SQLView and added in function calls. DO NOT OPEN QUERY IN DESIGN VIEW. Access query designer cannot resolve these joins. Would have to join nested subqueries to enable Design View.
Note I have spelled address with two d's, modify as you see fit.
SELECT Sheet1.code, [time], [type of error], FirstName, LastName, age, address
FROM Sheet4 RIGHT JOIN (Sheet3 RIGHT JOIN (Sheet2 RIGHT JOIN Sheet1
ON StrToHex([Sheet2].[code]) = StrToHex([Sheet1].[code]))
ON StrToHex([Sheet3].[code]) = StrToHex([Sheet1].[code]))
ON StrToHex([Sheet4].[code]) = StrToHex([Sheet1].[code]);

Related

Retrieving Columns with count greater than 1 - Google Sheet Query

I'm using Google sheets, and I want to get the data from one sheet to another where I want only the columns with count > 1.
Let's say we have 3 columns A, B, and C. I tried the following (the first sheet name is "Form Responses 1"):
I thought about using a query in the second sheet as: =query('Form Responses 1'!A1:Z, "Select A having count (A) >1 union select B having count (B) >1 union select C having count (C) > 1"). But I got a parse error where it seems that union and having are not supported in google sheets query.
How can I achieve this (whether it's using query or any other Google sheets function that can work)?
More details:
The first sheet contains info about exercises conducted during a lecture and it gets its data from a Google Form (so the responses are fed in this sheet). Here is a screenshot of it:
Please note that the form is divided into sections. When the user selects the course, the attendance, the participation, and adds a comment, then they go to the next section, the next section will be based on the selected course, the newly opened section will have the exercise name and rating questions (the exercise name is a dropdown list with items that are prefilled and specific to the selected course). That's why, you can see that "exercise name" and "rate the exercise" columns are repeated because we have 2 sections in this form.
The second sheet should contain the data of a selected course only (either mobile dev or web dev) which can be achieved easily through a query with a where clause. But, in addition to that, it shouldn't contain the empty columns of "exercise name" and "rate the exercise" as they correspond to another section. So, it should have only one exercise name column and one rating column that correspond to the selected course. Here is a screenshot if we only use a query with where clause without removing the extra name and rating columns:
Here is a screenshot with the desired result:
Thanks.
why not use just:
=QUERY('Form Responses 1'!A1:Z, "select A,B,C,D,E,F,G where F is not null", 1)
Use "OR" condition
Eg:-
QUERY(Data!A:R,"select A, N, P where N>0 or P>0")
where A column has country and N, P columns have population values

Using Different Parameters in Same excel Workbook for SQL

I have an excel Workbook with 2 sheets.
In each sheet I have a Query that extracts data from an external Server through SQLserver.
in Sheet1, Cell A1, I have the value 1000
and starting from Cell B2 I need the Query to get all the Students that have score more than 1000
I write the code in Excel in Data > Connection Properties > Definition > Command text
My code goes as follows:
SELECT Results.ID, Results.Score
FROM Results
Where Results.Score > ?
When I press OK, I am prompted to select a cell to be used as a parameter instead of the '?' Character
and then I get all Students ID & Score of Students with score more than 1000
and when I change the Cell A1 in Sheet1
Now in Sheet2, Cell A1, I have the Value 5
and starting from Cell B2 I need the Query to get all students in Grade 5
My code goes as follows:
SELECT Students.ID, Students.Grade
FROM Students
WHERE Students.Grade = ?
and When I press ok, the query runs without asking me to assign cell to hold the '?' Parameter , and it uses the parameter from the first query
How can I tell excel that I need a different parameter for each Query
Thanks in advance
Well, I searched a lot for anyone who have the same problem as me and I could't find So I thought it must be something I am doing to cause the problem
To facilitate creating the second query, I used to make a replicate of the 1st sheet and change the SQL command of the 2nd Query in the 2nd Sheet, which I found causes the replication of the parameter used
So the solution is simply create new query for each new Sheet

VBA macro for excel. Mark row if cells in column A are the same but different in column C

I do not have any code yet as I dont know VBA that much or at all.
I got excell sheet with 4 columns. Column A is main group and C is subgroups within groups from column A.
i need to mark somehow rows where within same JobID, WFID is the same and where WFID is different within same JobID.
JobID TaskID WFID
39822 913914 Complete
39822 913915 no complete
37941 905439 Complete
37941 905440 Complete
Would you be able to help pleasE?
You do not really need macros to identify your rows.
Simply put this formula in a new column
=COUNTIFS($A$1:$A$8,A1,$C$1:$C$8,"<>"&C1)
Wherever there are different values in col C for same value of col A it will throw a 1 else 0
If you want to highlight, I recommend using conditional formatting based on the value of your new column with (0/1) values.
Hope this answers your query.

Retain Specific values in Excel sheet and remove others and get count of how many times repeated vbscript

I want to remove all in excel data except for rows 'containing' the name "abc".I am trying to update the excel sheet and then get the count of how many times each duplicate has repeated.The output should be another excel sheet in which i have the condensed duplicate values along with the count i got previously.
What I have done: To get the count of duplicate value I used this:
=COUNTIF($A$1:$A$8, A1
But how can i remove the other values and put the remaining in a new Excel Sheet.
Add a "RowNo" column with the row number or any other Row Id. Next use Microsoft Query in the output Excel file e.g.:
SELECT S1.Val, COUNT(S1.Val) FROM `C:\Book1.xls`.`Sheet1$` as S1
INNER JOIN `C:\Book1.xls`.`Sheet1$` as S2
WHERE S1.Val = S2.Val and S1.RowNo > S2.RowNo
GROUP BY S1.Val
Additionally to remove data not containing e.g. 'abc' you can add another condition to the WHERE clause: S1.Val NOT LIKE "abc". See below:
SELECT S1.Val, COUNT(S1.Val) FROM `C:\Book1.xls`.`Sheet1$` as S1
INNER JOIN `C:\Book1.xls`.`Sheet1$` as S2
WHERE S1.Val = S2.Val and S1.RowNo > S2.RowNo AND S1.Val NOT LIKE "*abc*"
GROUP BY S1.Val
Feel free to test different SQL with my AddIn: link.
To set this up via VBscript:
Step 1: Create an Excel with this Microsoft Query
Step 2: Create a VBscript that will refresh the Microsoft Query in the Excel file (See an example here of how to connect to an Excel file from VBscript link).

compare all fields in access using vba/sql

I know I can compare values between two tables, but I have not needed to do it for more than 2 or 3 fields up to this point so comparing them each individually hasnt been an issue, I used code such as this:
DoCmd.RunSQL "INSERT INTO Issues
SELECT Eligibility.[Member Id]
, Eligibility.[Sex Code]
, Eligibility.State
FROM Eligibility LEFT JOIN Ref
ON Eligibility.[Sex Code] = Ref.[Sex Code]
WHERE (((Ref.[Sex Code]) Is Null));"
now however, i need to compare about 140 different fields. is there a better way to do this than writting 140 sql statements and running them all one by one?
i want it to find where fields dont contain the same info and then pull the entire row from both tables,or at the very least the value in the 5th column, member id, and then i can run another query to pull the entire row off of that value if need be (so i can look at both at the same time) and paste them into another table and highlight the cells where the mismatches occur.
both tables are in the same database
both tables have the same structure, but the second table might not have all of the values from the first, so i need to find a way to have it match the rows based on the member ID before it starts comparing the rows.
You can compare using DAO pretty easily. Using the .Fields() argument on a recordset you get all the different fields in the actual recordset.
This lets you do something like:
Sub exampleSQLComparison()
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
'.... set those recordsets via SQL statements
For Each f In rs1.Fields
If rs1.Fields(f) <> rs2.Fields(f) Then
Debug.Print "Mismatch found for " + f
End If
Next f
End Sub
If your queries are similar and the only thing you are changing is a single field (for example an ID) you should be able to modify the logic accordingly.