Any Bored Database Gurus?

Thread Tools
 
Search this Thread
 
Old Aug 1, 2006 | 11:28 AM
  #1  
UrbanCowboy's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2000
Posts: 481
Likes: 0
From: Westminster, CO
Any Bored Database Gurus?

Here's the scenario.

We have a table called Catalogue. Important fields are

Tot_1
Tot_2
Tot_3
Tot_4

We have a table called appl_status. Important Fields are
Status_num
Status

Thirs and final table we'll call data_file. Important Fields are
Status

Okay; so here's the deal. I want to get a count on data_file for how many of each status exist. So let's say...

select count(*), status from data_file group by status.

These counts need to be put in the tot_# fields from the Catalogue field. The status field, however, is not a number, it's a character.

That's where appl_status comes into play. Appl_status maps the Status character to the Status_num which as I explained related to the Tot_# fields in the Catalogue table.

Any thoughts on how I can get the Count(*), status from the data_file table, into the Catalogue Tot_# fields usiing appl_status as a translation?
 
Reply
Old Aug 1, 2006 | 11:31 AM
  #2  
vader716's Avatar
Senior Member
Joined: Jan 2003
Posts: 2,079
Likes: 0
From: Pikesville, MD
Any key linkage?
 
Reply
Old Aug 1, 2006 | 11:32 AM
  #3  
UrbanCowboy's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2000
Posts: 481
Likes: 0
From: Westminster, CO
I'm not familiar with the term. But I'm farily confident the answer is No.
There are no other fields which can help relate this data.

Ever used Informix as your main database?
 
Reply
Old Aug 1, 2006 | 11:35 AM
  #4  
vader716's Avatar
Senior Member
Joined: Jan 2003
Posts: 2,079
Likes: 0
From: Pikesville, MD
Ok so is Tot_1 the total count for status 1
Tot_2 for status 2, etc?

oh and for appl table is status_num the count for each status that you will be updating the cat table?
 
Reply
Old Aug 1, 2006 | 11:38 AM
  #5  
UrbanCowboy's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2000
Posts: 481
Likes: 0
From: Westminster, CO
Yea Basically.

data_file will have like 5+ status codes (A, N, X, BD, F)

Catalogue has several Tot_# fields that represent these status codes.

Appl_Status translate. Status_num = 1; status = "A"
Status_num = 2; status="N"

EDIT: Status_Num is NOT the count. It's simply a number... 1 through like 10. The count of the status codes will be in the hundreds or thousands.
 
Reply
Old Aug 1, 2006 | 11:46 AM
  #6  
UrbanCowboy's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2000
Posts: 481
Likes: 0
From: Westminster, CO
select count(*), status from data_file group by status

Results:
1209 A
39 X
9889 N

Data from appl_status...

status_num, status
1, A
2, X
3, N

Catalogue table needs updated.
Tot_1 = 1209
Tot_2 = 39
Tot_3 = 9889

See?
 
Reply
Old Aug 1, 2006 | 12:04 PM
  #7  
vader716's Avatar
Senior Member
Joined: Jan 2003
Posts: 2,079
Likes: 0
From: Pikesville, MD
Yea I'm trying to figure out the insert or update statement without using keys that link the tables
 
Reply

Trending Topics

Old Aug 1, 2006 | 12:07 PM
  #8  
UrbanCowboy's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2000
Posts: 481
Likes: 0
From: Westminster, CO
Our vendor for this system has a program that does this but it takes 15 minutes to do this one time and we need to do it 1200 times over night. I have no doubt this can be done Much much faster with a bit of SQL. Worse case scenario; I have to do it one status at a time (hard coded) rather than bulk. But it should still take less than a minute each run.
 
Reply
Old Aug 1, 2006 | 12:08 PM
  #9  
vader716's Avatar
Senior Member
Joined: Jan 2003
Posts: 2,079
Likes: 0
From: Pikesville, MD
I think I've got the select part down just trying to figure out the updating part..

SELECT Count(data_file.Status) AS CountOfStatus, data_file.Status, appl_status.status_num
FROM data_file, appl_status
where data_file.status = appl_status.status
GROUP BY data_file.Status, appl_status.status_num;

This returns

Count of Status.........Status...............Status_num
3................................a................ .........1
2................................b................ .........2
4................................c................ .........3
6................................d................ .........4

etc
 

Last edited by vader716; Aug 1, 2006 at 12:11 PM.
Reply
Old Aug 1, 2006 | 12:10 PM
  #10  
UrbanCowboy's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2000
Posts: 481
Likes: 0
From: Westminster, CO
I dont think this is useful information but here it is.

The 1200 entries I mentioned are 1200 different data_file tables. If I can do this with one; I can easily modify my script to do all 1200. Anyway; the true name of data_file is something like dfs_323984

There is a field in Catalogue called dfs_name
The dfs_name field contains the name of the data_file table.

That's a link....sorta.... but I dont think that's useful.

UC
 
Reply
Old Aug 1, 2006 | 12:35 PM
  #11  
vader716's Avatar
Senior Member
Joined: Jan 2003
Posts: 2,079
Likes: 0
From: Pikesville, MD
Well I think I have it but it is hokey...there is a better way but I should study some....

Unless I'm misunderstanding the problem.

I created a table called temptable.

I ran the following which updates the temptable with the data shown in an above post.

insert into temptable

SELECT Count(data_file.Status) AS CountOfStatus, data_file.Status, appl_status.Status_num
FROM data_file, appl_status
WHERE (((data_file.Status)=[appl_status].[status]))
GROUP BY data_file.Status, appl_status.Status_num;



Then I run the following:

UPDATE Catalogue, temptable SET Catalogue.Tot_4 = [TEMPTABLE].[COUNTOFSTATUS]
WHERE [temptable].[status_num] = "4"
This would need to be run for each status_num.

Like I said there is a way to make this more streamline by pulling the status num, creating a variable and running it for each unique status_num but I'd do that in VB.

This is very hokey but it will theoretically work. If I understandthe problem correctly.

End results of a once empty table:

 

Last edited by vader716; Aug 1, 2006 at 12:39 PM.
Reply
Old Aug 1, 2006 | 12:52 PM
  #12  
UrbanCowboy's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2000
Posts: 481
Likes: 0
From: Westminster, CO
Looks good. Unfortunately Access is not allowing me to do a Count on the text field from data_file. I get an ODBC Call failure on the linked table. ARGH.

Edit: Kinda irrelevant I guess; I won't be using Access in final implementation but rather Informix via shell script. Let me see...
 
Reply
Old Aug 1, 2006 | 12:58 PM
  #13  
UrbanCowboy's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2000
Posts: 481
Likes: 0
From: Westminster, CO
Doh; Informix says
298: COUNT(DISTINCT ...) may be used only with a simple column.
 
Reply
Old Aug 1, 2006 | 12:59 PM
  #14  
vader716's Avatar
Senior Member
Joined: Jan 2003
Posts: 2,079
Likes: 0
From: Pikesville, MD
depending upon the size of the data I'd copy it out work on it in SQL server or Access and the import the results back in....
 
Reply
Old Aug 1, 2006 | 01:02 PM
  #15  
UrbanCowboy's Avatar
Thread Starter
|
Senior Member
Joined: Mar 2000
Posts: 481
Likes: 0
From: Westminster, CO
Originally Posted by vader716
depending upon the size of the data I'd copy it out work on it in SQL server or Access and the import the results back in....
7 Million records a night.
 
Reply



All times are GMT -4. The time now is 05:09 AM.