OdinsDream
Well-known Member
- Joined
- May 19, 2002
- Messages
- 541
Hi, I'm constructing a database to replace a previous table kept in excel. The table worked like this:
Where the 'x' represents activity at that particular site. I reconstructed this in my database, and in the large table, I'm storing the Number (along with other details), and in a smaller lookup table, I'm storing:
Details.Number
Details.ActiveSite
So, for the above data, my lookup table would be:
Now then, I've constructed this SQL statement, but I'm trying to recreate the previous table, for backwards compatibility... that is, I want ALL the numbers shown on the left, but I'd like to tease out the ActiveSite column and "spread it out" across the top, like it was before.
Here's my statement so far:
Any help is greatly appreciated. My problem is, if I restrict it by saying "WHERE sd.ActiveSite = 1", then I lose certain numbers...
Code:
Number Site1 Site2 Site3
12 x x
14 x x x
16 x x
31 x
82 x x
Where the 'x' represents activity at that particular site. I reconstructed this in my database, and in the large table, I'm storing the Number (along with other details), and in a smaller lookup table, I'm storing:
Details.Number
Details.ActiveSite
So, for the above data, my lookup table would be:
Code:
Number Active Site
12 1
12 3
14 1
14 2
14 3
16 1
16 2
31 1
82 2
82 3
Now then, I've constructed this SQL statement, but I'm trying to recreate the previous table, for backwards compatibility... that is, I want ALL the numbers shown on the left, but I'd like to tease out the ActiveSite column and "spread it out" across the top, like it was before.
Here's my statement so far:
Code:
SELECT si.Number, sd.ActiveSite
FROM Info AS si
FULL JOIN Details AS sd ON
si.Number = sd.Number
ORDER BY si.Number;
Any help is greatly appreciated. My problem is, if I restrict it by saying "WHERE sd.ActiveSite = 1", then I lose certain numbers...