Results 1 to 3 of 3
  1. #1
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192

    Concatenating rows & records

    Hi everybody,
    I do have a database in which yarn prices are fixed for yarn counts of different units. I have the following table structures:
    1) tblUnits – Fields: UnitID (PK), UnitName (eg. A, B, C ….)
    2) tblCounts – Fields: CountID(PK), ContName (eg. 60S, 80S, 100S…….)


    3) tblYarnPricingMeeting – Fields: MeetingID (PK), Meeting# (Text), MeetingDate, CountID(CK), UnitID(CK), RateFixed (Currency)
    All the units say A, B & C (UnitID: 1,2,3)may run 100S count(CountID: 1). In the pricing meeting, eg. meeting # 001 (MeetingID: 101), prices for different units for a particular count may be same or differ. For MeetingID: 101 the tblYarnPricingMeeting is as follows:
    MeetingID
    Meeting#
    MeetingDate
    CountID
    UnitID
    RateFixed
    101
    101
    22-Aug-2011
    1
    1
    850
    101
    101
    22-Aug-2011
    1
    2
    850
    101
    101
    22-Aug-2011
    1
    3
    900

    In the Underlying Query for report, the Units should be concatenated meeting wise, count wise rate wise as follows:
    MeetingID
    Meeting#
    MeetingDate
    CountName
    UnitName
    RateFixed
    101
    101
    22-Aug-2011
    100S
    A, B
    850
    101
    101
    22-Aug-2011
    100S
    C
    900

    Is it possible? There is a solution in bluclaw-db.com. However, it is related to one ID & not for multiple ID.


    Alex

  2. #2
    Alex Motilal is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2008
    Location
    Coimbatore, India
    Posts
    192
    I am rephrasing the data as follows

    tblYarnPricingMeeting
    MeetingID Meeting# MeetingDate CountID UnitID RateFixed
    101 101 22-Aug-2011 1 1 850
    101 101
    22-Aug-2011 1 2 850
    101 101
    22-Aug-2011 1 3 900

    Resultant Query
    MeetingID Meeting# MeetingDate CountName UnitName RateFixed
    101 101
    22-Aug-2011 100S A, B 850
    101 101 22-Aug-2011 100S C 900

    Alex

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You can do this in a query but it'll be an ugly formula, it would have to have every possible unitID in the formula and I don't how possible that is with your dataset, I think I'd be more inclined to just use a crosstab query.

    First step would be this:

    Code:
    SELECT YP.MeetingID, YP.MeetingNum, YP.MeetingDate, YP.CountID, tblUnits.UnitName, YP.RateFixed
    FROM tblYarnPricingMeeting AS YP LEFT JOIN tblUnits ON YP.UnitID = tblUnits.UnitID;
    Save this as QUERY1 (NOTE I changed your meeting# to meetingnum, using special characters in field names is a bad practice and will only cause problems with your coding)

    next make this query
    Code:
    TRANSFORM Count(Query1.CountID) AS CountOfCountID
    SELECT Query1.MeetingNum, Query1.MeetingDate, Query1.RateFixed
    FROM Query1
    GROUP BY Query1.MeetingNum, Query1.MeetingDate, Query1.RateFixed
    PIVOT Query1.UnitName;
    It will list rows for every unit type you have which may be more useful to you than having it concantentated. If you really must have it concantenated then you would write a new query based on the crosstab query (the second query) that would contcantenate the fields.

    I've never found a reason to do this type of concantenation so someone may have a sleeker solution

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Concatenating fields from matching records
    By MWMike in forum Queries
    Replies: 1
    Last Post: 10-28-2010, 10:49 PM
  2. Concatenating and then exporting to excel
    By canfish in forum Queries
    Replies: 6
    Last Post: 08-18-2010, 09:52 AM
  3. Concatenating 3 Felds
    By Dody in forum Queries
    Replies: 2
    Last Post: 02-19-2010, 02:38 PM
  4. Concatenating many fields into one field
    By olidav911 in forum Programming
    Replies: 1
    Last Post: 08-13-2009, 05:14 AM
  5. Concatenating from a table or query.
    By stephen c in forum Programming
    Replies: 3
    Last Post: 07-13-2009, 08:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums