formating data in specific format

C

cliff

Hi, I have the following data in table

mytable

sr.no. rndval
1 14
1 26
1 32
1 48
1 49
2 15
2 27
2 33
2 42
2 46

I have present the above data in followind format in report

sr.No. rndval1 rndval2 rndval3 rndval4
rndval5
1 14 26 32 48
49
2 15 27 33 42
46


kindly help me to solve out


cliff
 
J

John Spencer

If you want to display them in order then you could use one of two methods.

If they don't need to be in separate fields, you could use Duane
Hookom's concatenate function.
Quoting Duane Hookom

I use a generic Concatenate() function. The code is listed below with
both ADO and DAO. There are comments regarding which lines to comment or
uncomment based on which library you prefer. Access 97 is mostly DAO
while the default for 2000 and newer is ADO.

See:
http://www.rogersaccesslibrary.com/OtherLibraries.asp#Hookom,Duane

Otherwise you could use a ranking query to assign value to the rndVal
fields and then use that as the source of a cross tabl query

QRank:
SELECT A.[SrNo], A.RndVal, Count(B.RndVal) as Rank
FROM YourTable as A LEFT JOIN YourTable as B
ON A.[SRNo] = B.[SrNo]
AND A.rndVal > B.RndVal
GROUP BY A.[SrNo], A.RndVal

Now use that query as the source for a crosstab query that would look
something like the following. You will need to enter the one RndVal#
entry in the "In" clause for each (maximum number) of rndVal columns
that will be returned.

TRANSFORM First(Q.RndVal) as TheValue
SELECT Q.[SrNo]
FROM QRank as Q
GROUP BY Q.[SrNo]
Pivot "RndVal" & Rank + 1 in
("RndVal1","RndVal2","RndVal3","RndVal4","RndVal5","RndVal6")

Now you should be able to build a report based on the above query.

'====================================================
John Spencer
Access MVP 2002-2005, 2007-2008
The Hilltop Institute
University of Maryland Baltimore County
'====================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top