Solved

Concatenate text string in crosstab query Access 2003

Posted on 2009-04-08
4
1,278 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
  • 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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