Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
Hi,
This is My StoredProcedure :

SQL
GO
ALTER PROCEDURE [dbo].[uspGetVote](@TeamID INT,@CardID INT)

AS

BEGIN


SELECT AVG(VoteValue) AS [AverageVoteValue] FROM Vote
WHERE TeamID=@TeamID and CardID=@CardID and LastModifiedDateTime between getDate()-7 and getDate()
end



When i execute this procedure its returns a null.

Please give a correct code for that.

Thank you.
Posted
Comments
Suvendu Shekhar Giri 4-Sep-15 1:15am    
There is nothing worng with your stored procedure. Check whether there is any data available in your table on the applied filter. Try running the query the DB IDE.
Member 11559509 4-Sep-15 1:18am    
yes i have data on my table
Schatak 4-Sep-15 4:10am    
Can you post your table or data, because procedure is fine, probably your table have no data.
Herman<T>.Instance 4-Sep-15 4:31am    
WHERE expand with:
AND VoteValue IS NOT NULL
MUKUL GOEL 6-Sep-15 7:37am    
As you are taking average of VoteValue, so must check whether any value in VoteValue column is Null or Not. My suggestion is to include one more condition in where clause saying VoteValue IS NOT NULL

1 solution

Either you can mention isnull i.e.

SQL
SELECT AVG(ISNULL(VoteValue,0)) AS [AverageVoteValue] FROM Vote
WHERE TeamID=@TeamID and CardID=@CardID and LastModifiedDateTime between getDate()-7 and getDate()


OR

you can add a condition like what MUKUL GOEL said.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900