Mike Eghtebas
asked on
Cross-tab?
I have table "tDefinitionSpecific" and I want to make "tFieldData." Cross-tab query doesn't quite do it?
tDefinitionSpecific
========================== ==
Issue_ID Def_I FieldName
------ -------- ----------
2 40 Sponsor
2 90 Sales
3 21 Sponsor
3 23 Sales
4 46 Sales
6 100 Sponsor
tFieldData
========================== ========== ====
Issue_ID Sponsor Sales
-------- ---------- ----------
2 40 90
3 21 23
4 46
6 100
This is for Access 2007.
What is the best way to accomplish this?
Thank you.
tDefinitionSpecific
==========================
Issue_ID Def_I FieldName
------ -------- ----------
2 40 Sponsor
2 90 Sales
3 21 Sponsor
3 23 Sales
4 46 Sales
6 100 Sponsor
tFieldData
==========================
Issue_ID Sponsor Sales
-------- ---------- ----------
2 40 90
3 21 23
4 46
6 100
This is for Access 2007.
What is the best way to accomplish this?
Thank you.
ASKER
IrogSinta,
For now I suppose I could use it this way, but it would be much better without specifying
Sum(IIf([FieldName]="SPONS OR"
just like cross-tab query.
Mike
For now I suppose I could use it this way, but it would be much better without specifying
Sum(IIf([FieldName]="SPONS
just like cross-tab query.
Mike
ASKER
re:> The above would give you:
It doesn't. It sums because you have:
Sum(IIf([FieldName]="SPONS OR",[Def_I ],0))
Have you tried witht the data?
It doesn't. It sums because you have:
Sum(IIf([FieldName]="SPONS
Have you tried witht the data?
should be able to do a crosstab.
Set IssueID as Row Header
FieldName as the column Header
Def_I as the Value
But instead of selecting Count or sum for the Def_I column, select First
Set IssueID as Row Header
FieldName as the column Header
Def_I as the Value
But instead of selecting Count or sum for the Def_I column, select First
As usual, fyed is right on!
ASKER
Thank fyed,
If the original data was like:
Issue_ID Def_I FieldName
------ -------- ----------
2 40 Sponsor
2 90 Sales
2 91 Sales <-- this rwo gets eliminated
3 21 Sponsor
3 23 Sales
4 46 Sales
6 100 Sponsor
If the original data was like:
Issue_ID Def_I FieldName
------ -------- ----------
2 40 Sponsor
2 90 Sales
2 91 Sales <-- this rwo gets eliminated
3 21 Sponsor
3 23 Sales
4 46 Sales
6 100 Sponsor
ASKER
I suppose a union query should do this also.
but that is not what the original data you provided looks like. Given this new dataset, what would you want the output to look like?
ASKER
I had tried cross-tab before posting. But it failed hence I decided to get some opinion. I agree that I didn't give a good data set to start with. With the revise data above, It is expected to return:
Issue_ID Sponsor Sales
2 40 90
2 0 91
3 21 23
4 0 46
6 100 0
Issue_ID Sponsor Sales
2 40 90
2 0 91
3 21 23
4 0 46
6 100 0
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Using yor solution I have:
SELECT T1.Issue_ID, T1.FieldName, T1.Definition_ID, Count(T2.*) as Level
FROM tIssueSpecific as T1
INNER JOIN tIssueSpecific as T2
ON T1.Issue_ID = T2.Issue_ID
AND T1.FieldName = T2.FieldName
AND T1.Definition_ID >= T2.Definition_ID
GROUP BY T1.Issue_ID, T1.FieldName, T1.Definition_ID
And it give the attached error (no error number please see the image).
After I changed it to:
SELECT T1.Issue_ID, T1.FieldName, T1.Definition_ID, Count(*) as Level_A
FROM tIssueSpecific as T1
INNER JOIN tIssueSpecific as T2
ON T1.Issue_ID = T2.Issue_ID
AND T1.FieldName = T2.FieldName
AND T1.Definition_ID >= T2.Definition_ID
GROUP BY T1.Issue_ID, T1.FieldName, T1.Definition_ID
It runs but I have to check the output.
thx
QryError.bmp
SELECT T1.Issue_ID, T1.FieldName, T1.Definition_ID, Count(T2.*) as Level
FROM tIssueSpecific as T1
INNER JOIN tIssueSpecific as T2
ON T1.Issue_ID = T2.Issue_ID
AND T1.FieldName = T2.FieldName
AND T1.Definition_ID >= T2.Definition_ID
GROUP BY T1.Issue_ID, T1.FieldName, T1.Definition_ID
And it give the attached error (no error number please see the image).
After I changed it to:
SELECT T1.Issue_ID, T1.FieldName, T1.Definition_ID, Count(*) as Level_A
FROM tIssueSpecific as T1
INNER JOIN tIssueSpecific as T2
ON T1.Issue_ID = T2.Issue_ID
AND T1.FieldName = T2.FieldName
AND T1.Definition_ID >= T2.Definition_ID
GROUP BY T1.Issue_ID, T1.FieldName, T1.Definition_ID
It runs but I have to check the output.
thx
QryError.bmp
ASKER
Perfect.
Thank you.
Thank you.
FROM tDefinitionSpecific
GROUP BY tDefinitionSpecific.Issue_
The above would give you:
Issue_ID Sponsor Sales
2 40 90
3 21 23
4 0 46
6 100 0