Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Concatenate text string in crosstab query Access 2003

Posted on 2009-04-08
4
Medium Priority
?
1,345 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 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

721 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