如何在两个具有聚合功能的日期之间选择数据?

问题描述:

嗨!
我正在尝试使用聚合(求和)功能在两个日期的基础上从表中选择数据.但它返回的是NULL值..我正在sql server 2008中使用此Querry.

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.

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)



我给存储过程指定的两个日期都存在于数据库中,但它仍然返回NULL.



both the dates which i give to store procedure are exist in data base but it still returns NULL.

可能会有所帮助.

May be It will help.

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