Group value Query (1 Viewer)

Babycat

Member
Local time
Today, 14:20
Joined
Mar 31, 2020
Messages
275
Hi Everyone

I want to build a query that group data as the attached picture. Can anyone please help me?

1662376314761.png
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:20
Joined
May 7, 2009
Messages
19,245
google Allen Browne ConcatRelated function.
 

plog

Banishment Pending
Local time
Today, 02:20
Joined
May 11, 2011
Messages
11,646
In Access both Name and Type are reserved words:


You shouldn't name any object or field with any of those on that list--makes coding and querying a little more dificult. I recommend prefixing both those fields with what they are names and types of (ComponentType, ComponentName, etc.)
 

Babycat

Member
Local time
Today, 14:20
Joined
Mar 31, 2020
Messages
275
In Access both Name and Type are reserved words:


You shouldn't name any object or field with any of those on that list--makes coding and querying a little more dificult. I recommend prefixing both those fields with what they are names and types of (ComponentType, ComponentName, etc.)
Dear Plog,

Thank for your notice, actually there data it was made in Excel, just for demo purpose.
 

Babycat

Member
Local time
Today, 14:20
Joined
Mar 31, 2020
Messages
275
How did you come up with that result? I don't understand how the Resistor got an ID of 2 instead of 4.
The ID is not essential there, they can be changed, the desired data might store in a new table...
The main idea is to combine the items having same type into single row with comma between.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:20
Joined
Oct 29, 2018
Messages
21,474
The ID is not essential there, they can be changed, the desired data might store in a new table...
The main idea is to combine the items having same type into single row with comma between.
Hi. Thank you for the clarification. I would probably use something like this then.
Code:
SELECT Min(ID) AS ID, SimpleCSV("SELECT [Name] FROM TableName WHERE [Type]='" & [Type] & "'") AS [Name], [Type]
FROM TableName
GROUP BY SimpleCSV("SELECT [Name] FROM TableName WHERE [Type]='" & [Type] & "'"), [Type]
(untested)
You can find the SimpleCSV() function here.
Hope that helps...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:20
Joined
Feb 19, 2002
Messages
43,293
Naming all your autonumbers "ID" just causes confusion. That is what prompted question in #5.
 

Babycat

Member
Local time
Today, 14:20
Joined
Mar 31, 2020
Messages
275
Hi. Thank you for the clarification. I would probably use something like this then.
Code:
SELECT Min(ID) AS ID, SimpleCSV("SELECT [Name] FROM TableName WHERE [Type]='" & [Type] & "'") AS [Name], [Type]
FROM TableName
GROUP BY SimpleCSV("SELECT [Name] FROM TableName WHERE [Type]='" & [Type] & "'"), [Type]
(untested)
You can find the SimpleCSV() function here.
Hope that helps...
Hi theDBguy

It works,

1662576095285.png


The actual SQL in my case:
Code:
SELECT SimpleCSV("SELECT [Designator] FROM TBLBOMDETAIL WHERE [BOMID]= 1 and [IKYPN] = '" & [IKYPN] & "'",", ") AS Designator_N, TBLBOMDETAIL.IKYPN AS PartType, Count(TBLBOMDETAIL.IKYPN) AS BomCount
FROM TBLBOMDETAIL
GROUP BY SimpleCSV("SELECT [Designator] FROM TBLBOMDETAIL WHERE [BOMID]= 1 and [IKYPN] = '" & [IKYPN] & "'",", "), TBLBOMDETAIL.IKYPN;
 

theDBguy

I’m here to help
Staff member
Local time
Today, 00:20
Joined
Oct 29, 2018
Messages
21,474
Hi theDBguy

It works,

View attachment 103098

The actual SQL in my case:
Code:
SELECT SimpleCSV("SELECT [Designator] FROM TBLBOMDETAIL WHERE [BOMID]= 1 and [IKYPN] = '" & [IKYPN] & "'",", ") AS Designator_N, TBLBOMDETAIL.IKYPN AS PartType, Count(TBLBOMDETAIL.IKYPN) AS BomCount
FROM TBLBOMDETAIL
GROUP BY SimpleCSV("SELECT [Designator] FROM TBLBOMDETAIL WHERE [BOMID]= 1 and [IKYPN] = '" & [IKYPN] & "'",", "), TBLBOMDETAIL.IKYPN;
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom