Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Linking Multiple Tables

Author  Topic 

needsqlhelp
Starting Member

3 Posts

Posted - 2014-12-08 : 02:53:40
Here is a picture of what I need, because Im a terrible explainer.

http://oi62.tinypic.com/13ye62o.jpg

Let's say every student in the left table, has a corresponding table to the right. If we were to take the average of all the classes in the corresponding table, how would you be able to transfer that in the table to the left, assuming there could be thousands of these individual tables.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-12-08 : 12:41:05
The picture doesn't help me understand your problem at all. I need to see some sample data or a better explanation.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

needsqlhelp
Starting Member

3 Posts

Posted - 2014-12-08 : 14:21:45
Alright, Ill try explaining it better.

Let's say on one table, the MAIN table, you have 1000 entries/tuples. Every single tuple/row corresponds to 1 student at that school. So essentially in the MAIN table, you have 1 table of 1000 students. There are 3 attributes/columns to the MAIN table with 1000 students. You have on the left Student ID, in the middle Student Name, and on the right their total GPA (Average of all their grades).

Now, the GPA attribute/column of the MAIN table, needs to derive its data from some place else. So, each student in the MAIN table with 1000 rows, will have their own table of classes. So essentially, there is 1 MAIN table of 1000 rows(students), and 1,000 other tables that correspond to each student in the MAIN table. These "corresponding" tables will have the list of classes for each students, and an individual grade next to each of their classes. The total average of all these classes in the "corresponding" tables is the GPA, which I need to show back in the MAIN table's GPA column.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-12-08 : 14:28:06
Yikes. Terrible database design.

You'll need to use dynamic SQL if the table names are stored in a table: http://www.sommarskog.se/dynamic_sql.html

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

needsqlhelp
Starting Member

3 Posts

Posted - 2014-12-08 : 18:50:48
Yeah someone mentioned to me dynamic sql, I guess Ill start there. Thanks for the help Im a total noob at SQL, I need it for a few websites I have in mind. I havent worked much with dynamic pages before, just static.
Go to Top of Page
   

- Advertisement -