| Author |
Topic |
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2011-12-08 : 21:38:12
|
Procedure not returning the data from Temp Table.ALTER PROCEDURE [dbo].[FetchGroupComm](@AgentCode int,@FromDate datetime,@ToDate datetime)ASBEGIN DECLARE @RowNo int,@MainID int,@tAmount float,@eComm float,@eTDS float,@eNet floatSET @RowNo = 1DECLARE @DateTable AS TABLE (RowNo int IDENTITY(1,1),MainID int)DECLARE @OutTable AS TABLE (RowNo int IDENTITY(1,1),tAmount float,eComm float,eTDS float,eNet float)INSERT INTO @DateTableSelect MainID from Comms where IssueDate >=@FromDate and IssueDate <=@ToDate and AgentCode = @AgentCode group by MainID;SELECT * FROM @DateTableWHILE @RowNo < = ( SELECT MAX(RowNo) FROM @DateTable) BEGIN SET @tAmount=0 SET @eComm =0 SET @eTDS =0 SET @eNet =0 Select @MainID=MainID from @DateTable Where RowNo = @RowNo Select @tAmount =COALESCE(round(sum(vAmount),2),0),@eComm = COALESCE(round(sum(Comm),2),0) ,@eTDS = COALESCE(round(sum(LessTDS),2),0) ,@eComm = COALESCE(sum(round(NetComm,2)),0) from Comms where IssueDate >=@FromDate and IssueDate <=@ToDate and MainID = @MainID and AgentCode = @AgentCode; if @tAmount > 0 BEGIN INSERT INTO @OutTable (tAmount,eComm,eTDS,eNet) VALUES (@tAmount ,@eComm ,@eTDS,@eNet) END SET @RowNo = @RowNo +1 END Select * from @OutTable END VB6/ASP.NET------------------------http://www.nehasoftec.com |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-08 : 23:41:31
|
you don't need to use while loopSelect MainID, tAmount = COALESCE(round(sum(vAmount),2),0), eComm = COALESCE(round(sum(Comm),2),0), eTDS = COALESCE(round(sum(LessTDS),2),0), eNet = COALESCE(sum(round(NetComm,2)),0) from Comms where IssueDate >=@FromDate and IssueDate <=@ToDate and AgentCode = @AgentCode;group by MainID KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
ravininave
Posting Yak Master
111 Posts |
Posted - 2011-12-09 : 00:48:41
|
quote: Originally posted by khtan you don't need to use while loopSelect MainID, tAmount = COALESCE(round(sum(vAmount),2),0), eComm = COALESCE(round(sum(Comm),2),0), eTDS = COALESCE(round(sum(LessTDS),2),0), eNet = COALESCE(sum(round(NetComm,2)),0) from Comms where IssueDate >=@FromDate and IssueDate <=@ToDate and AgentCode = @AgentCode;group by MainID KH[spoiler]Time is always against us[/spoiler]
No, I must have to use loop. Kindly suggest me why it's not returning data from temp tableVB6/ASP.NET------------------------http://www.nehasoftec.com |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2011-12-09 : 01:03:00
|
quote: No, I must have to use loop
any particular reason why ?quote: Kindly suggest me why it's not returning data from temp table
I don't have access to the data to see where is the problem. Put some debug statement in there to see if your SELECT statement returns any records. KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|