Crazy CrossTab problems

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 9
Reputation: muek is an unknown quantity at this point 
Solved Threads: 0
muek muek is offline Offline
Newbie Poster

Crazy CrossTab problems

 
0
  #1
Dec 29th, 2008
Hi there,
I'm completely lost.

I have 3 tables:
- work (workID, description)
- machine (machineID, name)
- work_machine (machineID, workID, hours)

What I want is to obtain a result similar to:

work, machine1, machine2
A , 1 ,
B , 3 , 5

The problem is that the number of works and the number of machines is unknown.

Can anyone help?
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 276
Reputation: kanaku is on a distinguished road 
Solved Threads: 15
kanaku's Avatar
kanaku kanaku is offline Offline
Posting Whiz in Training

Re: Crazy CrossTab problems

 
0
  #2
Dec 30th, 2008
I think what you can do on your work_machine table is have references to the workid and machineid...

work_machineID | workID | machineID
1 | A | 1
2 | B | 3
3 | B | 5

Then just select from this table where workID = 'A';
Last edited by kanaku; Dec 30th, 2008 at 1:43 am. Reason: wrong label =(
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Crazy CrossTab problems

 
0
  #3
Dec 30th, 2008
Muke, seems you didn't normalize your database design!!
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 9
Reputation: muek is an unknown quantity at this point 
Solved Threads: 0
muek muek is offline Offline
Newbie Poster

Re: Crazy CrossTab problems

 
0
  #4
Dec 30th, 2008
Ok, I think that I haven't explain myself.

In table "work_machine" I have:
workID | machineID | hours
A | M1 | 1
B | M2 | 3
B | M1 | 5

Now I would like to know how to make the query to obtain the data in the format:

work | machine1 | machine2
A | 1 | 0
B | 3 | 5

Any idea?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Crazy CrossTab problems

 
0
  #5
Dec 30th, 2008
What's machine1 and machine2 ?? and what '0' in the first row in output?
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 9
Reputation: muek is an unknown quantity at this point 
Solved Threads: 0
muek muek is offline Offline
Newbie Poster

Re: Crazy CrossTab problems

 
0
  #6
Dec 30th, 2008
Hi,

machine1 and machine2 are rows from machine table
The 0 represents that machine2 don't do any "A" work

Originally Posted by RamyMahrous View Post
What's machine1 and machine2 ?? and what '0' in the first row in output?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Crazy CrossTab problems

 
0
  #7
Dec 30th, 2008
As I said, you've lack in your design, I am sorry but your database design is wrong. It need some normalization
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 276
Reputation: kanaku is on a distinguished road 
Solved Threads: 15
kanaku's Avatar
kanaku kanaku is offline Offline
Posting Whiz in Training

Re: Crazy CrossTab problems

 
0
  #8
Dec 30th, 2008
Hi again! Maybe you can try reading this: some-thread-on-sums.

Or this one @ daniweb.

Or ask RamyMahrous to describe the proper table structure. =)
If you know ASP, you can save other daniweb members from idiots like me by helping out in this forum.

Visit this thread
if your username starts with one of the following letters: B D F H J L N P R T X Y Z.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 9
Reputation: muek is an unknown quantity at this point 
Solved Threads: 0
muek muek is offline Offline
Newbie Poster

Re: Crazy CrossTab problems

 
0
  #9
Dec 30th, 2008
Hi RamyMahrus,

my DB design is the following:
I have 3 tables:
- work (workID, description)
- machine (machineID, name)
- work_machine (machineID, workID, hours)

Can you tell me what's wrong?


Originally Posted by RamyMahrous View Post
As I said, you've lack in your design, I am sorry but your database design is wrong. It need some normalization
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 2,065
Reputation: Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice Ramy Mahrous is just really nice 
Solved Threads: 256
Featured Poster
Ramy Mahrous's Avatar
Ramy Mahrous Ramy Mahrous is offline Offline
Postaholic

Re: Crazy CrossTab problems

 
0
  #10
Dec 30th, 2008
That's correct give me real sample data to all these tables + output you need not table just in english text what you need to extract from these tables.
BI Developer | LINKdotNET
B.Sc Computer Science, Helwan University
Technical blog | http://ramymahrous.wordpress.com
LinkedIn | http://www.linkedin.com/in/ramymahrous
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the MS SQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC