473,507 Members | 6,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Building a Complex Crosstab

I get extracts/reports from a corporate Sybase database. This is a
very very large transactional database, very little (or slow and
complex) reports/queries, so instead I have an all-inclusive query
run, dropped into a folder each night, and then do my data
analysis/mining via Access.

Now here's my problem

The DATA (stored as a Trait) is not stored in separate fields for each
trait .. here's an example

Identifier Trait_Name Trait_Value
12345 SeedNumber 147
12345 HarvestDate 4/15/2005
12345 Status Harvested
etc
There may be many rows for each identifier... as many rows as there
are unique trait and trait values assocaited with each identifier. Of
course the Trait_Value field is character.

Now what I want to do is to build a crosstab so that the data looks
like this..each identifier a row, each Trait_Name gets a field name
and the trait_values are converted to numeric, date or character to
conform to the type of data they are. I will have a separate field
for each Trait I want to use.
Identifier SeedNumber HarvestDate Status
12345 147 4/15/2005 Harvested
12346
12347 23 5/20/2001 Harvested
12348 Killed


This is what I have so far

in Access2003, QBE window, I built this

Identifier Seed:Iff([Trait_Name]="SeedNumber",[Trait_Value],"") etc
Group by First

So is this the correct way to do this? And how might I convert the
information to the correct format (Date, numeric).... I presume use
format()?

Maybe there's a way to more easily (and powerfully?) do this in SQL?
If so, I will have to learn that now as well.

Thanks
Jerry
Feb 20 '06 #1
10 2263
Hi Jerry,

Try pasting the following into the SQL section of a new query - check
that the table name is correct.

TRANSFORM First(tbl_Traits.Trait_Value) AS FirstOfTrait_Value
SELECT tbl_Traits.Identifyer
FROM tbl_Traits
GROUP BY tbl_Traits.Identifyer
PIVOT tbl_Traits.Trait_Name;

Feb 20 '06 #2
On 20 Feb 2006 14:06:20 -0800, "Anton" <an******@gmail.com> wrote:
Hi Jerry,

Try pasting the following into the SQL section of a new query - check
that the table name is correct.

TRANSFORM First(tbl_Traits.Trait_Value) AS FirstOfTrait_Value
SELECT tbl_Traits.Identifyer
FROM tbl_Traits
GROUP BY tbl_Traits.Identifyer
PIVOT tbl_Traits.Trait_Name;


I have Access 2000. I cannot find the TRANSFORM keyword in the help
file.

Is it in A2000? What does it do?

Thanks.
Feb 20 '06 #3
Wow Anton
Works great
I had a few syntax erros I had to work out, but I understand.
Is there a way to assign the proper format to the fields, text dates
to dates, text to numeric, etc? These seems not trivial since this
method does not explicitly identify the pivot columns.
Thanks for your help.
I learned something today with this..very powerful
Jerry

On 20 Feb 2006 14:06:20 -0800, "Anton" <an******@gmail.com> wrote:
Hi Jerry,

Try pasting the following into the SQL section of a new query - check
that the table name is correct.

TRANSFORM First(tbl_Traits.Trait_Value) AS FirstOfTrait_Value
SELECT tbl_Traits.Identifyer
FROM tbl_Traits
GROUP BY tbl_Traits.Identifyer
PIVOT tbl_Traits.Trait_Name;

Feb 21 '06 #4
Anton
In my limited knowledge, the only way I can think of to convert these
columns to proper format is to write this qry out to a table, and then
change the format of the fields. Not very elegant.
Jerry
On 20 Feb 2006 14:06:20 -0800, "Anton" <an******@gmail.com> wrote:
Hi Jerry,

Try pasting the following into the SQL section of a new query - check
that the table name is correct.

TRANSFORM First(tbl_Traits.Trait_Value) AS FirstOfTrait_Value
SELECT tbl_Traits.Identifyer
FROM tbl_Traits
GROUP BY tbl_Traits.Identifyer
PIVOT tbl_Traits.Trait_Name;

Feb 21 '06 #5
Looks like I can use the IN with the PIVOT function to specify which
Trait_Name entries I wish to convert to fields (specify order here as
well).

ex.
PIVOT tbl_Traits.Trait_Name IN ("Seednum","HarvestDate");

Try pasting the following into the SQL section of a new query - check
that the table name is correct.

TRANSFORM First(tbl_Traits.Trait_Value) AS FirstOfTrait_Value
SELECT tbl_Traits.Identifyer
FROM tbl_Traits
GROUP BY tbl_Traits.Identifyer
PIVOT tbl_Traits.Trait_Name;

Feb 21 '06 #6
On Tue, 21 Feb 2006 06:25:36 -0600, Jerome Ranch <ra*****@mchsi.com>
wrote:
Looks like I can use the IN with the PIVOT function to specify which
Trait_Name entries I wish to convert to fields (specify order here as
well).

Are you doing this in Access?

Please let me know.

Feb 21 '06 #7
yes
Are you doing this in Access?

Please let me know.

Feb 22 '06 #8
Hi agian Jerry,

When you run the query there is a variety of data types contained in
the Trait_Value field. If you want to sort/filter by date (or any other
type) you can do so at runtime eg: cdate, cint, cstr etc. Additionally,
you can also turn the crosstab query into a make table query and
reference records containing dates...or whatever else you want.
Possibly something like: (You need a reference to DAO 3.6)

Dim db As DAO.database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.openrecordset("SELECT * FROM tbl_Shism WHERE
isdate(FirstOfTrait_Value) ORDER BY FirstOfTrait_Value ; ")
Do Until rs.EOF
MsgBox rs("FirstOfTrait_Value")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing

Feb 22 '06 #9
Jerry,

Before you go running that little bit of code I just posted you might
like to change the msgbox to debug.print and show the debug window to
see the results, else you might be there for a while. Also note that
you can use the sql statement in the recordsource of the form to filter
the records. This should give you enough control over the data that you
want to show. Have fun Anton

Feb 22 '06 #10
Anton
Thanks for all your replies and help
This is where I am at now
I built the qry in SQL as you suggested

Here it is

TRANSFORM First(tblGT.texttraitvalue) AS FirstofTextTraitValue
SELECT tblGT.EUID
FROM tblGT
GROUP BY tblGT.EUID
PIVOT tblGT.TraitName In
("Seednum_1","HarvDate_1","STATUSCALL_1","SendGHDa te_1");

Note I used the IN statement to order and choose the TraitName I want
Here's an example of the results..nice, but as we agree, the format of
the fields is wrong. The numeric Seednum_1 and date Harvdate_1 and
SendGHDate_1 are still text values

EUID Seednum_1 HarvDate_1 STATUSCALL_1 SendGHDate_1
31341863 217 04/26/2004 Harvest 01/19/2004
31341864 79 04/14/2004 Harvest 01/19/2004
31341865 9 04/19/2004 Harvest 01/19/2004
31341866 54 04/19/2004 Harvest 01/19/2004
31341867 238 04/14/2004 Harvest 01/19/2004
There are indeed two more things to do.
1) Get these fields into the proper format, and
2) write this query to a table (so it can be joined with other tables
and have some use!)

As you suggest the best would be to do both simultaneously

I don't see how to convert these data in this query. Indeed Cdate()
takes a text date and converts it to real date,but CInt() does not
work for me when I use Cint() in a test database to convert a text
nuumeric to a real numeric. I get a "function not defined" error ..
so I used CDbl() and that does work.
I don't see how to use these conversions in this query SQL. I tried
placing them in the IN statement, but that clearly is wrong syntax.

So I did some reading on manipulating recordsets in my VBA
handbbooks.. I know enough to be dangerous, but not useful.
The code you suggested to write this out as a table is what needs to
done, but I really don't know how to implement it. I presume this
would be a module associated with the db. DAO 3.6 is referenced in
the datbase already. How do I call it? Does it run when I execute
the query?

Anton's code example
Dim db As DAO.database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.openrecordset("SELECT * FROM tbl_Shism WHERE
isdate(FirstOfTrait_Value) ORDER BY FirstOfTrait_Value ; ")
Do Until rs.EOF
MsgBox rs("FirstOfTrait_Value")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set db = Nothing
Why would I have to loop through to write this out to a table?
And there is still no way to make the data conversions

(if I call the qry above qryDataImport)

Dim db As DAO.database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.openrecordset("qryDataImport",dbOpenTable)
rs.Close
Thanks
Jerry


On 22 Feb 2006 13:17:51 -0800, "Anton" <an******@gmail.com> wrote:
Jerry,

Before you go running that little bit of code I just posted you might
like to change the msgbox to debug.print and show the debug window to
see the results, else you might be there for a while. Also note that
you can use the sql statement in the recordsource of the form to filter
the records. This should give you enough control over the data that you
want to show. Have fun Anton


Feb 24 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3198
by: Darleen | last post by:
I am seeking conceptual here on how to get started with a "3D Matrix" in Access. We run a training center which holds multiple classes in multiple cities at multiple times. So I need to create a...
1
17630
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
7
1355
by: Keith Work | last post by:
I have a table with a "Status" column (lookup field to the status table) and an "EscalationID" column (which may or may not be filled in). I want a report that indicates complete or not for 2...
2
3022
by: Sherman H. | last post by:
I have a few questions for crosstab and popup form questions: 1. I created a crosstab as follows: IT Financial Operation John 21 22 ...
4
8088
by: Judy | last post by:
I'm using Access 2003 and was wondering if it is possible to have a paramater selection within a crosstab query so that I wouldn't need to build a new table. I have a select query that I'm using...
7
1898
by: newguy | last post by:
I am trying to get the totals of a table by client by type of income. This query will get what I am looking for with each unique combination as a row: SELECT Sales.Client, BillCode.Type,...
8
6057
by: Penny | last post by:
(Access 2003 Multiuser Split DB, Windows XP Pro) Hi All, I would really appreciate just some basic tips on how to make a Crosstab Form based on a Crosstab Query. The query always has the same...
14
3470
by: Tina | last post by:
My employer tracks productivity/performance of clinicians (how much they bill) each week, its averages for the month, and the 6 months. These averages are compared to their expected productivity....
13
17110
by: salad | last post by:
Operating in A97. I didn't receive much of a response conserning Pivot tables in Access. Pivot tables are nice, but a CrossTab will work for me too. Using a Pivot table, one is actually...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.