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
 How to loop all records in store procedure?

Author  Topic 

EugeneLim11
Posting Yak Master

167 Posts

Posted - 2009-07-06 : 05:35:38
Hi all

I have a table name university with the following columns (UniversityID, Name, Address, Fax, Tel, Email, Reputation, Research, StaffStudentRatio)

As a result of changes in user's requirements, the user requested that anyone can rate the university reputation, research, staffstudentratio on a scale of 1-5 stars (implemented as integers) i.e. (a one to many relationships instead of 1 to 1 relationships).

Therefore I have designed another table named UniversityRating (RatingID, UniversityID, Reputation, Research, StaffStudentRatio)

Now what I need to do is to loop through each record in the university Table and insert the score for Reputation, Research and StaffStudentRatio as well as the UniversityID into the UniversityRating table (before I drop the columns in the University Table).

How do I do this ? your guidance is very much appreciated.

Thank you.

Regards,

Eugene

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-06 : 05:39:03
I assume RatingID is an identity column. Correct ?


insert into UniversityRating (UniversityID, Reputation, Research, StaffStudentRatio)
select UniversityID, Reputation, Research, StaffStudentRatio
from university



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

EugeneLim11
Posting Yak Master

167 Posts

Posted - 2009-07-06 : 05:44:02
Khtan,

Quote: " I assume RatingID is an identity column. Correct ?"

khtan you are right. It is an identity column.

Thank you for this simple solution. It is funny how blur I can be at times when applying what I know... I learnt this before in my 'beginning mssql' class but failed to apply it when I need to. ;( Feeling angry at myself for not spotting this simple but effective solution earlier...

Thank you for guiding me. God bless you!
Go to Top of Page
   

- Advertisement -