473,320 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Translate (convert, transform) multiple rows to single column

I am using Access I have this:

TABLE A
Slide Position GO ID
1
2
3
4 GO:0000166
4 GO:0000775
4 GO:0000795
4 GO:0000800
4 GO:0003677
5
6
7
8 GO:0042802
9
10 GO:0003779
10 GO:0005509


And would like to get this
TABLE B
Slide Position GO ID
1
2
3
4 GO:0000166, GO:0000775, GO:0000795, GO:0000800, GO:0003677
5
6
7
8 GO:0042802
9
10 GO:0005509, GO:0005856, GO:0007010, GO:0016020, GO:0051016


I already have created a table with "Slide Position" as primary key (TABLE C), but I don't get something similar to Table B

TABLE C with single column (and primary key)
Slide Position
1
2
3
4
5
6
7
8
9
10

Is there any way to create TABLE B?

thanks
Mar 15 '07 #1
2 4380
nico5038
3,080 Expert 2GB
For this you'll need a function to concatenate the different values into a string. This function can be stored in the modules section:

Expand|Select|Wrap|Line Numbers
  1. Function fncConcat(lngKeyField As Long) As String
  2.  
  3. Dim RS As DAO.Recordset
  4.  
  5. ' init function string
  6. fncConcat = ""
  7. Set RS = CurrentDb.OpenRecordset("select [GO ID] from [TAble A] where [Slide Position]=" & lngKeyField)
  8. If RS.EOF And RS.BOF Then
  9.    Exit Function
  10. End If
  11. RS.MoveFirst
  12. While Not RS.EOF
  13.    fncConcat = fncConcat & ", " & RS.fields("GO ID")
  14.    RS.MoveNext
  15. Wend
  16. ' remove first ", "
  17. fncConcat = Mid(fncConcat, 3)
  18.  
  19. End Function
  20.  
Now in a query use:

select distinct [Slide Position] , fncConcat([Slide Position]) from [Table A];

Nic;o)
Mar 17 '07 #2
NeoPa
32,556 Expert Mod 16PB
You could try looking in (Combining Rows-Opposite of Union ), where something similar is discussed.
Mar 20 '07 #3

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

Similar topics

6
by: Steven An | last post by:
Howdy, I need to write an update query with multiple aggregate functions. Here is an example: UPDATE t SET t.a = ( select avg(f.q) from dbo.foo f where f.p = t.y ), t.b = ( select sum(f.q)...
1
by: Closer | last post by:
I am new to XML and XSL, could someone please help? I have my XML and XSL files and can view the XML file with the stylesheet in my browser. Everything is fine. What I want to do is to...
3
by: gregory.sharrow | last post by:
I need to secure a datawarehouse table at the row level based on 1 to many keys on that table. A user should only see the rows they have access to. I need to be able to figure out which rows they...
7
by: Doug Heeren | last post by:
I have the following section of VB.NET code that transforms a simple dataset into an Excel xml workbook. It works fine for < 50 rows or so, but I have about 8,000 rows I need to transform. Is there...
10
by: JohnR | last post by:
I have a datatable as the datasource to a datagrid. The datagrid has a datagridtablestyle defined. I use the datagridtablestyle to change the order of the columns (so they can be different than...
7
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Run multiple SQL statements from ASP/ADO to an Oracle 10g. Please help, I'm trying to write an ASP page to use ADO to run a long query against an Oracle 10g database, to create tables,...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
2
by: Ch Pravin | last post by:
Hi All: I am having the following xml which i need to convert to excel using xslt. Please help me out. Afghanistan.xml <?xml version="1.0" encoding="utf-16"?> <Languages...
2
by: Michael | last post by:
It seems that a gridview allows us to delete only a single row at a time. How to extend this functionality to select multiple rows and delete all of the selected rows in a single stroke? just like...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.