473,791 Members | 3,074 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

query to group names from multiple fields

4 New Member
I have a table with 7 columns and 50 rows.
The first column is a unique ID#, the other 6 columns are for names. (Name1, Name2, ......Name6).
I need to create a 2 column query to extract the six names that belong to each unique ID. It doesn't matter that the ID will be repeated multiple times in the same column, I'll deal with that later. I just need to have the query results with an ID# column and a single Name column.

Any help would be appreciated.
Oct 8 '07 #1
4 1801
Killer42
8,435 Recognized Expert Expert
What sort of setup are we talking about? VB? What version? By "table" are you referring to a database table? What sort of database?
Oct 8 '07 #2
rush2112
4 New Member
Yes, it's an Access 2002 database table. I'd like it to be just a standard select query if possible, that I can use in creating a report. (It will actually be used as part of a cascading set of queries).
Oct 8 '07 #3
Killer42
8,435 Recognized Expert Expert
Yes, it's an Access 2002 database table. I'd like it to be just a standard select query if possible, that I can use in creating a report. (It will actually be used as part of a cascading set of queries).
In that case I'm going to move this over the the Access forum, as you'll find much more Access expertise there.
Oct 8 '07 #4
Jim Doherty
897 Recognized Expert Contributor
Yes, it's an Access 2002 database table. I'd like it to be just a standard select query if possible, that I can use in creating a report. (It will actually be used as part of a cascading set of queries).
Now this is by no means the only way to do this, neither is it as efficient as it could be. I have done it for you for 'clarity' rather than technical excellence... it merely gives you a very simple insight into calling a function, looping using an array and returning the result of that function to the SELECT query that called it.

Assumptions
Going by your example lets say you have a table called tblRush and fields names called ....Name1,Name2 ,Name3,Name4,Na me5,Name6
(This function is not concerned with your ID column as that is merely your row reference and not vital to this function)

Paste this fully commented function below into a module and save it

Expand|Select|Wrap|Line Numbers
  1.  
  2. 'This function takes the names of the six fields passed in
  3. 'and returns a concatenated string of values as the result
  4. 'Typical SQL syntax to use this example for a table called tblRush will be:
  5. ' SELECT tblRush.ID, fn_RushNames([Name1],[Name2],[Name3],[Name4],[Name5],[Name6]) AS Available_Names
  6. ' FROM tblRush;
  7.  
  8. ' You obviously need to amend the fieldnames and table name to suit you
  9.  
  10. 'define an zero based array consisting of the six variant variables passed in
  11.     Dim RushArray(5)
  12.     RushArray(0) = n1
  13.     RushArray(1) = n2
  14.     RushArray(2) = n3
  15.     RushArray(3) = n4
  16.     RushArray(4) = n5
  17.     RushArray(5) = n6
  18. 'loop through the elements of the array until the upper bound limit
  19. 'concatenatating each value and assigning a trailing comma
  20. 'skip over where a column might be null by converting to zero
  21. 'and testing for the zero value
  22.     For i = 0 To UBound(RushArray)
  23.         If Nz(RushArray(i), 0) = 0 Then
  24.             fn_RushNames = fn_RushNames
  25.         Else
  26.             fn_RushNames = fn_RushNames & RushArray(i) & ","
  27.         End If
  28.     Next i
  29. 'By now we have a string of values if at least one cell has a value
  30. 'separated by a comma so we strip off the trailing comma and return the result
  31. 'In the event of no values at all in any of the cells we test for a zero length
  32. 'string and return a value stating there are no values in ANY of the fields for
  33. 'that particular row
  34. If fn_RushNames = "" Then
  35.     fn_RushNames = "No values available for any or the six columns"
  36. Else
  37.     fn_RushNames = Left(fn_RushNames, Len(fn_RushNames) - 1)
  38. End If
  39. End Function
  40.  
Like I mentioned it is not the only way to do it. You can concatenate directly in the grid without using this function at all and test for nulls etc but I'll leave anyone else to give you their examples.

Regards

Jim
Oct 9 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
3087
by: Matthew Braumiller | last post by:
On Thu, 2 Oct 2003, "Gary Floam" <floam@comcast.net> wrote: >Sure you can do that. The easies way is to create a table of the last names >selected, and join that table into the query definition. > >If you write your own SQL, you can create a string something like > where LastName in ("Smith", "Jones", "Brown") > >Good luck >
3
579
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to make a query that selects from a table as desribed below .. I have a table (Volunteer) that has a member field (memnumber) and a number of fields that are headed in various categories and are yes/no formated
4
6038
by: Martin Lacoste | last post by:
(Access 2000) Two issues: Within a query, I need to return a field name as data (see eg. below). I need to search within 80 fields (same criteria) - is there a way to avoid 80 separate expressions (the 80 field names are stored in a table - can I get the query to look each of these up?)? Here's an example:
3
1981
by: dskillingstad | last post by:
I'd appreciate any help I can get. I'm not sure what I'm doing wrong, but.... I've searched these groups for some solutions but no luck. I have an unbound form (frmSearch), with several unbound text boxes on it and a command button bound to a macro which fires off a parameter query based on the criteria/string that the user types into the text boxes on frmSearch. My goal is to create a search form where the user can search by any of...
3
2098
by: Serious_Practitioner | last post by:
Good day, and thank you in advance for any assistance you can provide. I have a table in an Access 2000 .mdb file, and I've run into something odd and insolvable, at least for me. The database is for membership information. This particular table, called tblMembershipInfo, has fields/columns as follows - fldMemNum - Member Number fldActionDate - The date when the entry was made in that row - Data type is Date/Time, no format specified
9
2905
by: Jimbo | last post by:
Hello, I have a user request to build a form in an Access database where the user can check off specific fields to pull in a query. For example, let's say I have 10 fields in a table. The user wants to be able to check off anywhere between 1 and all 10 fields in a form and have it return a select query with just the fields that were checked off. There are multiple users, so not all users will be checking off the same fields. Some...
2
3382
by: Allen Anderson | last post by:
Hi, I'm trying to design contact (names and addresses) tables in an Access database. Some of the contacts represent vendors, some are board members of the organization, some are donors, some are neighbors of the organization, some are politicians, etc. Rather than create separate tables for each type of contact, I thought it would be better to have: one table with names/addresses one table with kinds of lists (vendors, board...
10
2112
by: Robert | last post by:
I am an attorney in a non-profit organization and a self-taught programmer. I'm trying to create a client db that will allow me to search for potential conflicts of interest based either on Social Security # or on Last Name. I've created two different tables with the following fields in each table: ClientInfo Client# (primary key) First Name Middle Name Last Name
9
4024
by: JJM0926 | last post by:
I'm trying to create a running totals query in access 97. I have followed the directions on how to do it from Microsofts website article id 138911. I took their code they had and replaced it with my fields. When I try to run it I get #errors in my RunTot column. I'm kinda new to this. Not sure if maybe I mistyped something wrong or is there a better way to do this? I have pasted the code. Any help would be greatly appreciated....
0
9669
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10428
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10207
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10156
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5435
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4110
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.