Firstly, I highly recommend not using triggers.
If you get a syntax error, make sure your partners are balanced, as well as your begin / ends . In your case, you have end (at the end), but don't start. You can fix this by simply removing end .
As soon as you fix this, you will most likely get some more errors, such as "columns x, y, z are not in the aggregate or group." This is because you have multiple columns that are not in any. You need to add thread.rating, thread.voters, etc. To your group or perform some kind of aggregate on them.
All this assumes that there are several records with the same stream identifier (i.e. this is not a primary key). If this is not so, then what is the purpose of the group :?
Edit:
I have a strong syntax error. I worked around it with a pair of correlated subqueries. I guessed about your table structure, so change it as needed and try the following:
--CREATE TABLE ThreadRating (threadid int not null, userid int not null, rating int not null) --CREATE TABLE Thread (threadid int not null, rating int not null, voters int not null) ALTER TRIGGER thread_rating ON threadrating AFTER INSERT AS UPDATE Thread SET Thread.rating = (SELECT (Thread.Rating * Thread.Voters + SUM(I.Rating)) / (Thread.Voters + COUNT(I.Rating)) FROM ThreadRating I WHERE I.ThreadID = thread.ThreadID) ,Thread.Voters = (SELECT Thread.Voters + COUNT(I.Rating) FROM ThreadRating I WHERE I.ThreadID = Thread.ThreadID) FROM Thread JOIN Inserted ON Inserted.ThreadID = Thread.ThreadID
If this is what you wanted, we can check the performance / implementation plan and change it if necessary. Perhaps we can get him to work with the group.
Alternatives to triggers
If you are updating data that affects ratings in only a few selected places, I would recommend updating ratings right there. The factoring of logic in a trigger is good, but it provides many problems (performance, visibility, etc.). This can help the function.
Consider this: your trigger will execute every time someone touches this table. Actions such as counting views, last updated dates, etc., will trigger this trigger. You can add logic to trigger a short circuit in these cases, but it gets complicated quickly.