By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

query help...

100+
P: 145
Here is the db with sample data.

http://download.yousendit.com/AAA18BC7520F196E

I want to use qryCrosstab and table "ALL" to achieve the result that would look like this query "qryFinalResult".

Table [ALL] has a field called filename and it stores the table names that qryFinalResult is using.

Is it Possible ????

Can someone please please help ? stuck with this for last 48 hours.
Feb 22 '07 #1
Share this Question
Share on Google+
11 Replies


100+
P: 145
Can someone pleas help ?

1. I use a vba to import bunch of excel files into individual tables.
Tables are named after the excel file. A field is created in these new
tables called "FileName" and it's populated with the filename.

2. I am doing this so I know what file the data came from

3. table "ALL" gets populated with all of these excel data and the
name of the file.

The crosstab is taking [ALL] table and aggegating hours, comp and
other data elements.

FinalResult is takign the crosstab and i m doing right join to pull
data from crosstab and all the data from each tables.

Is there a way I can only use table [ALL] and qrycrosstab to make my
look like qrufinalresult ?

Is there a vba that will do right join automatically between crosstab
and all the table in import (except table ALL)?

Here is the query that gives me all the table name.

SELECT DISTINCT MSysObjects.Name
FROM MSysObjects
WHERE (((MSysObjects.Name) Not Like "msys*" And (MSysObjects.Name) Not
Like "all*") AND ((MSysObjects.Type)=1));
Feb 22 '07 #2

100+
P: 145
Forum Owners: DELETE THIS POST IF NO ONE GOING TO ANSWER IT. I AM REALLY FRUSTRATED AND BEGGING FOR SOME HELP OR DIRECTIONS.
Feb 22 '07 #3

MMcCarthy
Expert Mod 10K+
P: 14,534
Forum Owners: DELETE THIS POST IF NO ONE GOING TO ANSWER IT. I AM REALLY FRUSTRATED AND BEGGING FOR SOME HELP OR DIRECTIONS.
Every effort is made to answer questions promptly but you have to be patient. All experts volunteer their time and your question will be attended to.

However, I will point out a couple of things. Most experts won't want to download your database onto their systems so you will help yourself by providing more information.

Post the metadata of all the tables invovled.
Posting Table/Dataset MetaData
Expand|Select|Wrap|Line Numbers
  1. Table Name=tblStudent
  2. StudentID; Autonumber; PK
  3. Family; String; FK
  4. Name; String
  5. University; String; FK
  6. MaxMark; Numeric
  7. MinMark; Numeric
Post the SQL code of the crosstab query as well as any other queries involved.

Mary
Feb 23 '07 #4

100+
P: 145
I am thinking of two different approach

Approach # 1 : Since all the data in tabl [ALL] , I would just like just this table with crosstab query made from this to make a query that will give same result that qryFinalResult does.

Approach # 2:
a. Create a query that will list all the tables except table [ALL]
Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT DISTINCT MSysObjects.Name
  3.        FROM MSysObjects
  4.        WHERE (((MSysObjects.Name) Not Like "msys*" And & _    
  5.        (MSysObjects.Name) Not Like "all*") AND ((MSysObjects.Type)=1));
b. Then use VBA to create right join from table [ALL] to these table
using ssn number.

Please let me know.

qryCrosstab
Expand|Select|Wrap|Line Numbers
  1.  
  2. TRANSFORM Sum([All].FileName) AS SumOfFileName
  3. SELECT [All].SocSecNum, Min([All].[Birth Date]) AS [MinOfBirth Date], Min([All].[Hire Date]) AS [MinOfHire Date], Max([All].Termination) AS MaxOfTermination, Max([All].[Rehire Date]) AS [MaxOfRehire Date], Sum([All].Compensation) AS SumOfCompensation, Sum([All].[Excluded Comp]) AS [SumOfExcluded Comp], Sum([All].Hours) AS SumOfHours, Sum([All].[Aniv Hours]) AS [SumOfAniv Hours], Sum([All].[History Comp]) AS [SumOfHistory Comp], Sum([All].[History Ex Comp]) AS [SumOfHistory Ex Comp]
  4. FROM [All]
  5. GROUP BY [All].SocSecNum
  6. PIVOT [All].FileName;

qryFinalResult
Expand|Select|Wrap|Line Numbers
  1. SELECT qryCrosstab.SocSecNum, qryCrosstab.[MinOfBirth Date], qryCrosstab.[MinOfHire Date], qryCrosstab.MaxOfTermination, qryCrosstab.[MaxOfRehire Date], qryCrosstab.SumOfCompensation1 AS Expr1, qryCrosstab.[SumOfExcluded Comp], qryCrosstab.SumOfHours, qryCrosstab.[SumOfAniv Hours], qryCrosstab.[SumOfHistory Comp], qryCrosstab.[SumOfHistory Ex Comp], qryCrosstab.[1110], qryCrosstab.[1317], qryCrosstab.[328], qryCrosstab.[429], qryCrosstab.[465], [328].Compensation, [328].[Excluded Comp], [328].Hours, [328].[Aniv Hours], [328].[Birth Date], [328].[Hire Date], [328].Termination, [328].[Rehire Date], [328].[History Comp] AS Expr1, [328].[History Ex Comp] AS Expr2, [429].Compensation, [429].[Excluded Comp], [429].Hours, [429].[Aniv Hours], [429].[Birth Date], [429].[Hire Date], [429].Termination, [429].[Rehire Date], [429].[History Comp] AS Expr3, [429].[History Ex Comp] AS Expr4, [465].Compensation, [465].[Excluded Comp], [465].Hours, [465].[Aniv Hours], [465].[Birth Date], [465].[Hire Date], [465].Termination, [465].[Rehire Date], [465].[History Comp] AS Expr5, [465].[History Ex Comp] AS Expr6, [1110].Compensation, [1110].[Excluded Comp], [1110].Hours, [1110].[Aniv Hours], [1110].[Birth Date], [1110].[Hire Date], [1110].Termination, [1110].[Rehire Date], [1110].[History Comp] AS Expr7, [1110].[History Ex Comp] AS Expr8, [1317].Compensation, [1317].[Excluded Comp], [1317].Hours, [1317].[Aniv Hours], [1317].[Birth Date], [1317].[Hire Date], [1317].Termination, [1317].[Rehire Date], [1317].[History Comp] AS Expr9, [1317].[History Ex Comp] AS Expr10
  2. FROM 1317 RIGHT JOIN 
  3. (1110 RIGHT JOIN 
  4. (((qryCrosstab LEFT JOIN 328 
  5. ON qryCrosstab.SocSecNum = [328].SocSecNum)
  6. LEFT JOIN 429 
  7. ON qryCrosstab.SocSecNum = [429].SocSecNum)
  8. LEFT JOIN 465 
  9. ON qryCrosstab.SocSecNum = [465].SocSecNum)
  10. ON [1110].SocSecNum = qryCrosstab.SocSecNum) 
  11. ON [1317].SocSecNum = qryCrosstab.SocSecNum;
Feb 23 '07 #5

MMcCarthy
Expert Mod 10K+
P: 14,534
I'm afraid I'm still a little confused about what you are trying to do.

Are you just trying to count the number of records in each table using a cross tab query and displaying the fields as laid out in the other query.

Mary
Feb 23 '07 #6

100+
P: 145
Yes,

I am trying to display all the fields from qryCrosstab and also display fields from each table across.
Feb 23 '07 #7

MMcCarthy
Expert Mod 10K+
P: 14,534
Looking at the information involved I would have to take a guess and say it can't be done. Adding all the extra fields will not allow you to group the crosstab query to give you a record count.

Mary
Feb 23 '07 #8

100+
P: 145
Hi Mary,

Here is how it's working. We receive census data from large clients like american express who has multiple sub companies. Employees moves from sub-company to sub-company. At the end of the year we receive census files from each sub-company.

We take the census data from each sub-copany and aggregate their hours, compensation,keep oldest hire date, keep recent term date and other data elements. This is what qyrCrosstab is doing.

Now in the final result we want to be able to display employees aggregate data and the original data across.

for example, if an employess listed in table 222 and 432 and 1452 then the result should look like below

ssn dob doh dot dor agg_comp agg_hrs 222.dob 222.doh 222.dot 222.dor

and so forth.

I am sorry if my issue is not clear. I understand it can be little confusing. I hope it's lil bit clear now.

Thanks everyone looking into this. I really appreciate it.
Feb 23 '07 #9

MMcCarthy
Expert Mod 10K+
P: 14,534
Hi Mary,

Here is how it's working. We receive census data from large clients like american express who has multiple sub companies. Employees moves from sub-company to sub-company. At the end of the year we receive census files from each sub-company.

We take the census data from each sub-copany and aggregate their hours, compensation,keep oldest hire date, keep recent term date and other data elements. This is what qyrCrosstab is doing.

Now in the final result we want to be able to display employees aggregate data and the original data across.

for example, if an employess listed in table 222 and 432 and 1452 then the result should look like below

ssn dob doh dot dor agg_comp agg_hrs 222.dob 222.doh 222.dot 222.dor

and so forth.

I am sorry if my issue is not clear. I understand it can be little confusing. I hope it's lil bit clear now.

Thanks everyone looking into this. I really appreciate it.
You can display in down but displaying it accross just using queries is very difficult.

The solution would be better proposed using recordsets. But this would require a table be created to store the data and how would you decide the number of tables involved. What is the largest number of possible tables.

I understand now what you are trying to do but don't think it's possible to represent the data accross because of the number of tables involved.

The solution I would look at is to create a master list of employees with date of birth and first table they are on. Then relate their entry in that table with a foreign key in all the other tables they appear in.

For example if they first appear in 222 and then in 432 then have a field in 432 table where for this record 222 is entered this can also be entered in table 222. Then everytime you reference employee x from the master list
you look up all tables where 222 is entered and return the data.

Sorry I can't think of another better solution to your problem.

Mary
Feb 23 '07 #10

MMcCarthy
Expert Mod 10K+
P: 14,534
Also have a look at this question to see if there is anything here that can help.

Combining Rows-Opposite of Union


Mary
Feb 23 '07 #11

P: 3
Rux
I'm Trying to get into the problem but I'm still confused.
Please try to explain some more the process
Feb 23 '07 #12

Post your reply

Sign in to post your reply or Sign up for a free account.