Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi !
I am trying to select data from table on the basis of two dates with the aggregate (sum) function. but it returns me the NULL value .. i am using this querry in sql server 2008.

SQL
select ISNULL(SUM  (SSI_MAIN_INFORMATION.PI_TOTAL_AMOUNT),0) AS TOTAL_SALES FROM SSI_MAIN_INFORMATION


WHERE PI_DATE >= CAST( @starting_date AS DATETIME)  AND  PI_DATE <= CAST ( @ending_date AS DATETIME)


both the dates which i give to store procedure are exist in data base but it still returns NULL.
Posted
Comments
grzelix25\ 16-Sep-12 9:28am    
does procedure without aggregation sum function returns any data? The query seems to be ok.

1 solution

May be It will help.

SQL
create procedure my_sp_name
@starting_date datetime,
@ending_date datetime
AS
BEGIN
	
	SET NOCOUNT ON;
	select ISNULL(SUM  (SSI_MAIN_INFORMATION.PI_TOTAL_AMOUNT),0) AS TOTAL_SALES FROM SSI_MAIN_INFORMATION

WHERE PI_DATE >=@starting_date  AND  
---if you store date and time both-----then use below expresson
PI_DATE < dateadd(d,1,@ending_date)
----if you store only date-----then use below expresson
PI_DATE <= @ending_date
END


Happy Coding
 
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