Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / November 2005

Tip: Looking for answers? Try searching our database.

Concatenate the records with same ID

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tim - 15 Sep 2005 19:29 GMT
Hi folks,

I need a help on my query.  I tried to concatenate the records which have
the same ID.  The following is the data in my table (Table1):

ID        Value
1        a
1        b
2        g
2        h
2        y
3        d
4        p
4        o
       
I need the output of my query like the following:

ID        Value
1        a, b
2        g, h, y
3        d
4        p, o

Could anyone show me how to do it?

Thanks in advance.

Tim
KARL DEWEY - 15 Sep 2005 20:03 GMT
This will work if you only have two Value to work with but I see more than
two in some cases of your example.  

Use two queries. I named the first one Query58 from Table20 so you can
change accordingly.

SELECT [RecID] & [SubID] AS Identification, First(Table20.Value) AS
FirstOfValue, Last(Table20.Value) AS LastOfValue
FROM Table20
GROUP BY [RecID] & [SubID];

SELECT Query58.Identification,
IIf([FirstOfValue]=[LastOfValue],[FirstOfValue],[FirstOfValue] & ", " &
[LastOfValue]) AS Type
FROM Query58;

> Hi folks,
>
[quoted text clipped - 24 lines]
>
> Tim
Michel Walsh - 15 Sep 2005 20:17 GMT
Hi,

In two steps. First, create a temp table that will get the two fields, and
unique ID (drop the table if it already exists, before)

SELECT DISTINCT id, iif(false, "", null) As concat INTO temp FROM mytable

Finally, create the various concatenations with a SET over a standard INNER
join:

UPDATE temp INNER JOIN myTable ON temp.id=mytable.id
SET temp.concat = ( temp.concat + ",  " )  & mytable.value

The result is now in the table temp.

Hoping it may help,
Vanderghast, Access MVP

> Hi folks,
>
[quoted text clipped - 24 lines]
>
> Tim
Duane Hookom - 15 Sep 2005 21:47 GMT
In addition to Michael's very cool SQL method, you can do this with the
generic Concatenate function found at
http://www.rogersaccesslibrary.com/OtherLibraries.asp#Hookom,Duane

Signature

Duane Hookom
MS Access MVP
--

> Hi,
>
[quoted text clipped - 42 lines]
>>
>> Tim
Tim - 19 Sep 2005 14:55 GMT
Thanks folks.  The info is very useful.

Tim.

> In addition to Michael's very cool SQL method, you can do this with the
> generic Concatenate function found at
[quoted text clipped - 46 lines]
> >>
> >> Tim
Gigi - 03 Nov 2005 13:40 GMT
Michel,

I have used your routine and it has done exactly what I wanted.. howver the
field I have joined is a cd track and the end result of all 20 tracks has
been truncated, I changed the format from text to memo in the temp file but
it has still truncated, can you help please?

many thanks

> Hi,
>
[quoted text clipped - 42 lines]
> >
> > Tim
Michel Walsh - 03 Nov 2005 15:11 GMT
Hi,

The query update can only handle 255 chars max, in a field, even if you turn
it into a memo, before being "stored", it has to be handled internally in a
standard field.

Vanderghast, Access MVP

> Michel,
>
[quoted text clipped - 56 lines]
>> >
>> > Tim
Gigi - 03 Nov 2005 15:35 GMT
Hi,

is there any other way I can do this?

many thanks

> Michel,
>
[quoted text clipped - 51 lines]
> > >
> > > Tim
Michel Walsh - 03 Nov 2005 17:24 GMT
Hi,

Have you tried the solution proposed by Duane?

Hoping it may help,
Vanderghast, Access MVP

> Hi,
>
[quoted text clipped - 63 lines]
>> > >
>> > > Tim
Gigi - 03 Nov 2005 21:16 GMT
ok will look at now, thanks again

> Hi,
>
[quoted text clipped - 70 lines]
> >> > >
> >> > > Tim
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.