![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
Hi Jeff, Your sample data looks like it has been processed a little bit. *You are displaying what you want your data to look like at the end. *But I have no idea what the raw data looks like at the beginning, so it would be quite difficult to offer any suggestions how to get to the end if you are already there. *Perhaps you could show a sample of what the raw data looks like. *What I am envisioning (guessing - from a relational standpoint) is that your raw data might look something like this: Detail Table locID * Item * 1 * * carrot * 1 * * carrot * 1 * * tomato * 1 * * carrot * 2 * * tomato * 1 * * cucumber * 1 * * cucumber * 2 * * tomato * 2 * * tomato * 1 * * tomato * 1 * * carrot .. Master Table locId *locName * 1 * *Garden1 * 2 * *Garden2 * 3 * *Garden3 .. from here you could do a group by query to tally up the produce and then crosstab that result. *This is the whole point of a relational system (RDBMS). Rich *** Sent via Developersdexhttp://www.developersdex.com*** |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Processed? ;-) So the data are in two table in 3NF. Roughly. What I'm representing is well locations and geologic units -- rather than garden veggies. My query generates: LocationName LithologyCode L1210 Tr L1210 Tf L1210 Tfsg L1210 Tfsh L1210 Tgsb L1210 Tgu L1210 Tgo L1210 Tggc L1210 Tgwr L1210 Tgud L1211 Tpr L1211 Tr L1211 Tfsg ...and what I would like to output through the query is a comma- delimited list of the LithologyCode of each LocationName. L1210 Tr, Tf, Tfsg, Tfsh, Tgsb, Tgu, Tgo, Tggc, Tgwr, Tgud L1211 Tpr, Tr, Tfsg What I suspect I need to write a VBA function to loop through the records for each LocationName and concatenate each subsequent LithologyCode with a comma and return that string -- in other words write a UDF. Here's where I guess that might go, in place of the "Max" grouping function... SELECT tblLocation.LocationName, Max((Select first(LithologyCode) from tblLithologicDescription U, tblLocation L where U.LocationID L.locationid)) AS Lith FROM tblLocation GROUP BY tblLocation.LocationName HAVING (((tblLocation.LocationName) In ("L1210","L1211"))); Anyway, I'm just fumbling my way through VBA, it seems like this is one of those cats that's been skinned before, and I wondered if Access already had a tool inside. (Last year wrote a confusing nested scalar query that's a nightmare to maintain, before realizing that - as long as I was committed to Jet - all would've been easier with the DLookup() function.) Thanks for your thoughts, jn On May 4, 10:01*am, Rich P <rpng... (AT) aol (DOT) com> wrote: Hi Jeff, Your sample data looks like it has been processed a little bit. *You ar e displaying what you want your data to look like at the end. *But I have no idea what the raw data looks like at the beginning, so it would be quite difficult to offer any suggestions how to get to the end if you are already there. *Perhaps you could show a sample of what the raw dat a looks like. *What I am envisioning (guessing - from a relational standpoint) is that your raw data might look something like this: Detail Table locID * Item * 1 * * carrot * 1 * * carrot * 1 * * tomato * 1 * * carrot * 2 * * tomato * 1 * * cucumber * 1 * * cucumber * 2 * * tomato * 2 * * tomato * 1 * * tomato * 1 * * carrot .. Master Table locId *locName * 1 * *Garden1 * 2 * *Garden2 * 3 * *Garden3 .. from here you could do a group by query to tally up the produce and then crosstab that result. *This is the whole point of a relational system (RDBMS). Rich *** Sent via Developersdexhttp://www.developersdex.com*** |
#6
| |||
| |||
|
|
http://www.mvps.org/access/modules/mdl0004.htm It is a VB function called fConcatChild() that does just what you are trying to do. Have fun. Bob Jeff <jnorvi... (AT) gmail (DOT) com> wrote innews:55517b6c-524e-4713-8460-9e099362615d (AT) z13g2000prh (DOT) googlegroups.co m: Processed? *;-) So the data are in two table in 3NF. *Roughly. *What I'm representing is well locations and geologic units -- rather than garden veggies. My query generates: LocationName * * LithologyCode L1210 * * Tr L1210 * * Tf L1210 * * Tfsg L1210 * * Tfsh L1210 * * Tgsb L1210 * * Tgu L1210 * * Tgo L1210 * * Tggc L1210 * * Tgwr L1210 * * Tgud L1211 * * Tpr L1211 * * Tr L1211 * * Tfsg ...and what I would like to output through the query is a comma- delimited list of the LithologyCode of each LocationName. L1210 * * Tr, Tf, Tfsg, Tfsh, Tgsb, Tgu, Tgo, Tggc, Tgwr, Tgud L1211 * * Tpr, Tr, Tfsg What I suspect I need to write a VBA function to loop through the records for each LocationName and concatenate each subsequent LithologyCode with a comma and return that string -- in other words write a UDF. Here's where I guess that might go, in place of the "Max" grouping function... SELECT tblLocation.LocationName, Max((Select first(LithologyCode) from tblLithologicDescription U, tblLocation L where U.LocationID L.locationid)) AS Lith FROM tblLocation GROUP BY tblLocation.LocationName HAVING (((tblLocation.LocationName) In ("L1210","L1211"))); Anyway, I'm just fumbling my way through VBA, it seems like this is one of those cats that's been skinned before, and I wondered if Access already had a tool inside. *(Last year wrote a confusing nested scalar query that's a nightmare to maintain, before realizing that - as long as I was committed to Jet - all would've been easier with the DLookup() function.) Thanks for your thoughts, jn On May 4, 10:01*am, Rich P <rpng... (AT) aol (DOT) com> wrote: Hi Jeff, Your sample data looks like it has been processed a little bit. *You ar e displaying what you want your data to look like at the end. *But I have no idea what the raw data looks like at the beginning, so it would be quite difficult to offer any suggestions how to get to the end if you are already there. *Perhaps you could show a sample of what the raw dat a looks like. *What I am envisioning (guessing - from a relational standpoint) is that your raw data might look something like this: Detail Table locID * Item * 1 * * carrot * 1 * * carrot * 1 * * tomato * 1 * * carrot * 2 * * tomato * 1 * * cucumber * 1 * * cucumber * 2 * * tomato * 2 * * tomato * 1 * * tomato * 1 * * carrot .. Master Table locId *locName * 1 * *Garden1 * 2 * *Garden2 * 3 * *Garden3 .. from here you could do a group by query to tally up the produce and then crosstab that result. *This is the whole point of a relational system (RDBMS). Rich *** Sent via Developersdexhttp://www.developersdex.com*** |
#7
| |||
| |||
|
|
That's the ticket -- had to be out there somewhere. Thanks all. On May 4, 2:11*pm, Bob Quintal wrote: It is a VB function called fConcatChild() that does just what you are trying to do. |
#8
| |||
| |||
|
|
There are lot's of those functions out on the web. I prefer the one at: http://www.rogersaccesslibrary.com/f...tion-to-concat enate-child-records_topic16&SID=4a7fb34e-c851-414693a4-b4c79b28-26c z2224.html -- Marsh I didn't know that one, but looking at the code, I think that I will |
|
Jeff wrote: That's the ticket -- had to be out there somewhere. Thanks all. On May 4, 2:11*pm, Bob Quintal wrote: It is a VB function called fConcatChild() that does just what you are trying to do. |
![]() |
| Thread Tools | |
| Display Modes | |
| |