Solved

Concatenate text string in crosstab query Access 2003

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

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now