Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
SQL
USE [EMO]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[Proc_RptDailySummaryPTCLBillsCollection_Result] 

	-- Add the parameters for the stored procedure here

		@DateFrom Date=Null,
	@DatTo Date=Null,
	@SubOfficeID varchar(200),
	@GroupID int,
	@ClerkName varchar(200),
	@Type varchar(200)


AS
BEGIN

	DECLARE @AgencyTable TABLE (GpoId int,OfcId int,Postal_Code int,Total_Bills int,Total_Amount BIGINT)

	--1. Billing Summary By GPO Name
	INSERT @AgencyTable (Postal_Code,OfcId,Total_Bills,Total_Amount)--GpoId,
	SELECT bil.GroupId,  Bil.SubOfficeId ,isnull(COUNT(Bil.ConsumerNumber),0) --AS Total_Bills
	   ,ISNULL(SUM(Bil.C_Amount),0) - ISNULL(SUM(Bil.Commission),0) --AS Total_Amount
    FROM BillTxnSO as Bil inner join pp_offices ofc On bil.GroupId = ofc.Group_Id and bil.SubOfficeId = ofc.OfficeCode and ofc.Postal_Code = bil.PostalCode 
    Where bil.GroupId = @GroupId   
    Group by bil.GroupId, Bil.SubOfficeId 
    
    --select * from @AgencyTable
SELECT   ofc.OfficeName as SubOffice,ofc.Group_ID as GroupID, ofc.Postal_Code as POCode,isnull(gpo.Total_Bills,0)as NoOfBills , isnull(gpo.Total_Amount,0) as Amount  
FROM @AgencyTable gpo 
INNER JOIN pp_offices ofc On ofc.Group_Id = gpo.GpoId and gpo.OfcId  = ofc.OfficeCode and gpo.Postal_Code=ofc.Postal_Code 
ORDER BY  ofc.OfficeName   
   
END


What I have tried:

I want to show record in application using this stored procedure but this do'not show any record
Posted
Updated 24-Apr-16 20:24pm
v3
Comments
Sinisa Hajnal 20-Apr-16 6:09am    
Execute it in Query analyzer and check the result. Do you get anything? If no, debug the procedure. If yes, check the parameters you're sending from the code. If they are OK then debug the code calling the procedure.
jaket-cp 25-Apr-16 4:31am    
Query analyzer - that is old school :)
It is a bit more of a mouth full now - Microsoft SQL Server Management Studio (or SSMS for short)

1 solution

The problem is with the part of the WHERE clause
SQL
AND TransDate  BETWEEN @DateFrom AND @DatTo

I suspect that you are using GEDATE() or DateTime.Now(); to derive the @DateFrom parameter and the Time is causing data to fall outside the range.

There are a couple of ways around this. Either change the parameter types to Date not DateTime
SQL
alter PROCEDURE [dbo].[Proc_RptDailySummaryPTCLBillsCollection_Result] 
 
	-- Add the parameters for the stored procedure here

	@DateFrom Date,
	@DatTo Date, -- ...etc

Or change the WHERE clause to read "Between the start of day @DateFrom and the end of the day @DateTo" - the last part is the same as saying "...and the start of the day after @DateTo" - which can be done like this:
SQL
AND TransDate  BETWEEN dateadd(dd, datediff(dd, 0, @DateFrom), 0) AND dateadd(dd, datediff(dd, 0, @DatTo) + 1, 0) 
 
Share this answer
 
v2
Comments
Member 12138525 25-Apr-16 2:10am    
still no record found
CHill60 25-Apr-16 4:35am    
Well all the date processing has now gone altogether I see.
Run the code in Query Analyser/SSMS? Uncomment the line select * from @AgencyTable
If that query returns data but your stored procedure does not, then the problem is with the JOIN to pp_offices - there is no matching data.
Can't help any further without sample data I'm afraid

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