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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 AVG in Stored Procedures

Author  Topic 

mapidea
Posting Yak Master

124 Posts

Posted - 2009-09-06 : 17:39:41
I have two stored procedures
1st
-------------
SELECT
tb_entry.feature_id,
tb_entry.user_id
FROM
tb_profile_feature_entry as tb_entry
INNER JOIN tb_profile_feature_entry_video as tb_video on tb_entry.entry_id=tb_video.entry_id AND tb_entry.feature_id=tb_video.feature_id AND tb_entry.user_id=tb_video.user_id

LEFT JOIN tb_profile_feature_entry_vote v ON tb_entry.entry_id=v.entry_id AND tb_entry.feature_id=v.feature_id AND tb_entry.user_id=v.user_id AND v.voter_id =@voter_id

WHERE v.entry_id is null

2nd
---------
SELECT
AVG(rating)
FROM
tb_profile_feature_entry_vote tb_vote
WHERE tb_vote.entry_id=@entry_id AND tb_vote.feature_id=@feature_id AND tb_vote.user_id=@user_id


Can I add AVG(rating) column in the first stored procedure meeting the condition.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-07 : 01:05:21
No.
The first query retieves only data without matching records in tb_profile_feature_entry_vote.
Because of "WHERE v.entry_id is null".

So you cannot do anything with data from tb_profile_feature_entry_vote.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mapidea
Posting Yak Master

124 Posts

Posted - 2009-09-07 : 12:25:48
I did it using temp tables. Thanks
Go to Top of Page
   

- Advertisement -