Solved

Concatenate text string in crosstab query Access 2003

Posted on 2009-04-08
4
1,302 Views
Last Modified: 2012-05-06
Hello experts,

I'm using a crosstab query in Access 2003 using a TRANSFORM and PIVOT

Field name:       qryWeightedTraits.tblTrait.name
From:                qryWeightedTraits1

As its a crosstab with multiple records I think I need an aggregate function, but I'm trying to get a text string of each of the records one record after the other i.e. the text of each record in a single string -  record1 & record2 & record3 .. ect.

So far I've used

(count() & first() & last()) As tblTrait_name

Which gives me the number of records, and text for two records, but I've got groups of records upto 4.

Is there some sort of 'concatenate' I can use in this situation that would give me the text from each record one after the other as a single string?

In the below code I've got this running in an iif()  
TRANSFORM Sum(qryWeightedTraits1.weightedTotal) AS SumOfweightedTotal
SELECT qryWeightedTraits1.speciesID, qryWeightedTraits1.SpeciesName, First(qryWeightedTraits.traitScoreID) AS traitScoreID, first(qryWeightedTraits.traitID) AS traitID, first( qryWeightedTraits.charID) AS charID, first(qryWeightedTraits.tblCharacter.name) AS tblCharacter_name, iif(count(qryWeightedTraits.tblTrait.name)=1, first(qryWeightedTraits.tblTrait.name), count(qryWeightedTraits.tblTrait.name) & first(qryWeightedTraits.tblTrait.name) & last(qryWeightedTraits.tblTrait.name)) AS tblTrait_name, first(qryWeightedTraits.value1) AS value1, sum(qryWeightedTraits.traitWeight) AS traitWeight, first(qryWeightedTraits.charWeight) AS charWeight, first(qryWeightedTraits.complexID) AS complexID, first(qryWeightedTraits.complexName) AS complexName
FROM qryWeightedTraits1
GROUP BY qryWeightedTraits1.speciesID, qryWeightedTraits1.SpeciesName
ORDER BY qryWeightedTraits1.SpeciesName
PIVOT qryWeightedTraits1.value1;

Open in new window

0
Comment
Question by:davecocks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24096144
you will need a user define function to do that..
post sample data from your crosstab query, and the result you want to see
0
 
LVL 1

Author Comment

by:davecocks
ID: 24096341
Legend! sounds exciting.

I hope xls files are OK. I can do txt or whatever, if you need it.

The 'orginal Data' file contains the equivalent of qryWeightedTraits1 from the code I posted.

The 'result' is how I hope it will look. If you need anything else just let me know. I can live without the count() of cells in the tblTrait_name field if its tricky.

Cheers

Original-Data.xls
Result.xls
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 24096779
see this sample db..
the function concatTrait is in module1

run query1 to see the result
sampleConcatDB.mdb
0
 
LVL 1

Author Closing Comment

by:davecocks
ID: 31570007
Fantastic!! Another great solution. Many thanks!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question